将当前位置和另一个位置放在MKMapKit中......

时间:2011-12-14 10:55:05

标签: iphone mkmapview

查询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中绘制两个位置之间的路径(如谷歌地图),我该怎么办?

1 个答案:

答案 0 :(得分:2)

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

mapView.showsUserLocation = YES

或者向mapView添加注释:

[mapview addAnnotation:myLocation]

但请阅读mkmapview的文档,您的实现不完整(缺少代理) 并查看示例

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