2011-12-14 72 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

相關問題