【问题标题】:Placing the current location and another location in MKMapKit......在 MKMapKit 中放置当前位置和另一个位置......
【发布时间】:2011-12-14 19:18:47
【问题描述】:

查询 1: 我正在使用 MKMapKit,我想在其中显示两个位置,一个是当前位置,另一个是固定位置我使用此代码...

 - (void)viewDidLoad
{
    mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,46,320,370)];
    [mapView setDelegate:self];
    [mapView setShowsUserLocation:TRUE];    
    [self.view addSubview:mapView];
    [mapView setMapType:MKMapTypeStandard];
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
   [locationManager startUpdatingLocation];
    MKCoordinateRegion region;
    MKCoordinateSpan span;
    span.latitudeDelta=0.9;
    span.longitudeDelta=0.9;
    CLLocationCoordinate2D location=mapView.userLocation.coordinate;
    location.latitude=13.160407;
    location.longitude=80.249562;
    region.span=span;
    region.center=location;
    geoCoder =[[[MKReverseGeocoder alloc] initWithCoordinate:mapView.userLocation.location.coordinate] autorelease];
    geoCoder.delegate = self;
    [geoCoder start];
    [super viewDidLoad];
}
- (MKAnnotationView *)mapView:(MKMapView *)MapView viewForAnnotation:(id<MKAnnotation>)annotation
{
 NSLog(@"View for Annotation is called");

if (NSClassFromString(@"MKUserLocation")==[annotation class]) {
    return nil;
}
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];

annView.pinColor = MKPinAnnotationColorGreen;
UIButton * btn = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
annView.rightCalloutAccessoryView = btn;
annView.animatesDrop=TRUE;

annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
pindropped = TRUE;
//[map addAnnotations:annotation];
return annView;}

我知道这个问题已经发布了很多次,但是我找不到任何解决我的问题的方法......

查询 2: 我需要在 MPMapKit 中的两个位置之间绘制路径(如在谷歌地图中),我该怎么做???

【问题讨论】:

    标签: iphone mkmapview


    【解决方案1】:

    1:你忘记了你的问题 ;-) 我假设,你没有看到你的位置...... 有两种方法: mapview 可以显示你的位置 ->

    mapView.showsUserLocation = YES

    或者你给 mapView 添加一个注解:

    [mapview addAnnotation:myLocation]

    但请阅读 mkmapview 的文档,您的实现不完整(缺少代表) 看看例子

    2:不像谷歌地图的javascript api那么容易。你必须从点到点画线。因此你需要谷歌的确切路线。

    【讨论】:

    • 不,我可以看到当前位置(来自模拟器)蓝点我找不到固定位置(我在代码中提到了一些坐标)
    • 您永远不会将固定位置添加到地图中。使用位置进行注释并将其添加到 mapView
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 2021-09-17
    • 1970-01-01
    相关资源
    最近更新 更多