1

在我的应用程序中有一个联系我们视图,该视图将有一个打开公司地址的按钮。所以我的代码在 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;
4

1 回答 1

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

你也可以参考这个链接

于 2013-07-05T10:12:23.430 回答