2012-10-12 38 views
2

與谷歌地圖我可以這樣做:蘋果地圖iOS 6計劃:如何顯示標註/別針?

http://maps.google.com/maps?q=[Title]@[Lat,Lon]

這將顯示在該地理定位的針,但在蘋果的文檔:

http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html

沒有辦法做到這一點?

+0

我有同樣的問題。我發現的最接近的是MKMapItem類方法openMapsWithItems。您可以使用它將一個或多個針腳放置到地圖應用程序中,並可以選擇顯示2點之間的方向。但是,我不知道如何添加標題添加您的引腳。 –

+0

我有同樣的問題。有沒有辦法做到這一點沒有MKMap?如果我能避免它,我寧願不帶它進來! – rcarver

回答

2
-(void)create_Map{ 


    for (int i=0; i<[arrayMap count]; i++) { 

     CLLocationCoordinate2D theCoordinate1; 
     theCoordinate1.latitude =[[[arrayMap objectAtIndex:i]objectForKey:@"latitude"] doubleValue]; 
     theCoordinate1.longitude =[[[arrayMap objectAtIndex:i]objectForKey:@"longitude"] doubleValue]; 
     addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:theCoordinate1]; 
     addAnnotation.mTitle=[[arrayMap objectAtIndex:i]objectForKey:@"place"]; 
     [_locMapView addAnnotation:addAnnotation]; 

    } 



    NSArray *coordinates = [_locMapView valueForKeyPath:@"annotations.coordinate"]; 
    // look for the minimum and maximum coordinate 
    NSLog(@"coordinates  %@ %i ",coordinates,[arrayMap count]); 

    CLLocationCoordinate2D maxCoord = {-90.0f, -180.0f}; 
    CLLocationCoordinate2D minCoord = {90.0f, 180.0f}; 
    for(NSValue *value in coordinates) { 
     CLLocationCoordinate2D coord = {0.0f, 0.0f}; 
     [value getValue:&coord]; 
     if(coord.longitude > maxCoord.longitude) { 
      maxCoord.longitude = coord.longitude; 

      NSLog(@"maxCoord.longitude  %f ",maxCoord.longitude); 
     } 
     if(coord.latitude > maxCoord.latitude) { 
      maxCoord.latitude = coord.latitude; 
     } 
     if(coord.longitude < minCoord.longitude) { 
      minCoord.longitude = coord.longitude; 
     } 
     if(coord.latitude < minCoord.latitude) { 
      minCoord.latitude = coord.latitude; 
     } 
    } 
    // create a region 
    MKCoordinateRegion region = {{0.0f, 0.0f}, {0.0f, 0.0f}}; 
    region.center.longitude = (minCoord.longitude + maxCoord.longitude)/2.0; 
    region.center.latitude = (minCoord.latitude + maxCoord.latitude)/2.0; 
    // calculate the span 
    region.span.longitudeDelta = maxCoord.longitude - minCoord.longitude; 
    region.span.latitudeDelta = maxCoord.latitude - minCoord.latitude; 

    [_locMapView setRegion:region animated:YES]; 

    // [_locMapView setRegion:region animated:TRUE]; 
    // [_locMapView regionThatFits:region]; 


} 
3

確實使用MKMapItem類方法openMapsWithItems。

訣竅是MKMapItem對象有一個name屬性。如果您在傳遞給openMapsWithItems的MKMapItem對象上設置name屬性,那麼這些項目在打開時會在地圖中命名。

所以步驟如下:

爲您的針腳創建一個MKPlacemark。您可以提供緯度/經度座標或地址信息。

從您的地標創建MKMapItem 在地圖項目上設置name屬性。

致電[MKMapItem openMapsWithItems:launchOptions:]打開地圖應用程序並在指定位置放置一個別針。請注意,您可以使用此呼叫拖放多個別針,或在兩點之間提供步行或駕車路線。

0

這裏有一個例子:

CLLocationCoordinate2D location = CLLocationCoordinate2DMake(_transaction.lat.doubleValue, _transaction.lon.doubleValue); 

MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:location addressDictionary:nil]; 
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark]; 
mapItem.name = _transaction.merchant_name; 
[mapItem openInMapsWithLaunchOptions:@{MKLaunchOptionsMapTypeKey : @(MKMapTypeStandard), 
             MKLaunchOptionsShowsTrafficKey : @YES}];