2011-12-14 115 views
0

查询1: 我正在使用MKMapKit,我想在其中显示两个位置,一个是当前位置,另一个是固定位置我使用此代码...将当前位置和另一个位置放在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中的两个位置之间绘制方式(如在谷歌地图中) ,我该怎么办?

回答

2

1:你忘了你的问题;-)我认为,你看不到你的位置... 有两种方式: 的MapView可以显示您的位置 - >

mapView.showsUserLocation = YES

或您添加注释到的MapView:

[mapview addAnnotation:myLocation]

,但请务必仔细阅读的MKMapView的文档,你的实现是不完整的(缺少代表) 并看看示例

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

+0

不,我可以看到当前位置(来自模拟器)蓝色点我找不到固定位置(我已经提到了我的代码中的一些坐标) – Icoder 2011-12-14 11:29:24