苹果地图:获取方向 [英] Apple Map : get direction

查看:121
本文介绍了苹果地图:获取方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Apple地图在两个地方之间取得方向?
我可以提供这两个地方的纬度和经度吗?
可以在我的应用程序本身显示方向吗?
或者是否需要显示苹果iPhone的内建Map应用程序的方向?

How can I use Apple map for getting direction between two places? I can provide the latitude and longitude of that two places? Is it possible to show the direction in my app itself? or Should I need to show the direction in the in built Map app of apple's iPhone?

推荐答案

您可以发送用户在iOS6之前的导航应用程序或iOS6之前的Google地图。

You can send user to navigation app in iOS6 or google maps prior to iOS6.

以下是一个示例代码:

        Class itemClass = [MKMapItem class];
        if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) {
            // iOS 6 MKMapItem available
            MKPlacemark* place = [[MKPlacemark alloc] initWithCoordinate:_targetLocation addressDictionary:nil];
            MKMapItem* destination = [[MKMapItem alloc] initWithPlacemark:place];
            destination.name = @"Name Here!";
            NSArray* items = [[NSArray alloc] initWithObjects: destination, nil];
            NSDictionary* options = [[NSDictionary alloc] initWithObjectsAndKeys:
                                     MKLaunchOptionsDirectionsModeDriving,
                                     MKLaunchOptionsDirectionsModeKey, nil];
            [MKMapItem openMapsWithItems:items launchOptions:options];
        } else {
            // Pre-iOS 6
            CLLocationCoordinate2D coords = _lastLocation.coordinate;

            NSString *stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%g,%g&daddr=%g,%g", coords.latitude, coords.longitude, _targetLocation.latitude, _targetLocation.longitude];
            NSURL *url = [NSURL URLWithString:stringURL];
            [[UIApplication sharedApplication] openURL:url];
        }

这篇关于苹果地图:获取方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆