使用iOS5中的坐标打开地图应用

时间:2013-06-29 12:44:36

标签: ios5 ios6 maps coordinates

在我的应用程序中,有一个联系我们视图,其中有一个按钮可以打开公司的地址。所以我的代码在iOS6中运行良好,我知道它应该与iOS 5不同,但找不到合适的方法。 这是我的代码:

// Check for iOS 6
BOOL iOS6 = NO;

Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)])
    iOS6 = YES;

switch (buttonIndex) {
    case 0:

        if (iOS6) 
        {
         // Create an MKMapItem to pass to the Maps app
         CLLocationCoordinate2D coordinate =
         CLLocationCoordinate2DMake(26.375561, 50.170305);
         MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate
         addressDictionary:nil];
         MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
         [mapItem setName:@"Industrial Projects Technologies"];
         // Pass the map item to the Maps app
         [mapItem openInMapsWithLaunchOptions:nil];
         }

        else
        {
            // Use the iOS 5 method
        }
        break;

1 个答案:

答案 0 :(得分:4)

将此代码用于iOS5,以显示源到目标路径

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.apple.com/?daddr=%@,%@&saddr=%@,%@",latitudeOfDestinationLocation,longitudeOfDestinationLocation,latitudeOfSourceLocation,longitudeOfSourceLocation]]];

在地图中显示特定点

maps.google.com/?q=latitude,longitude

示例:maps.google.com/?q=26.375561,50.170305

您也可以参考this link