从您的应用内部调用地图以获取路线 - iOS5 iOS6 [英] Call Maps for directions from inside your app - iOS5 iOS6

查看:143
本文介绍了从您的应用内部调用地图以获取路线 - iOS5 iOS6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个奇怪的问题:我的应用程序应该能够调用iOS中的内置地图(包括5.1和6)。事实证明它在iOS6下运行良好,但在iOS5.1下运行不正常。调用iOS6中的地图并跟踪从saddr到daddr的路线,但是当我在iOS5中时,地图应用程序被调用,但只有一个引脚被放在daddr上。由于某些未知原因,初始坐标(saddr)没有显示,也没有跟踪方向。

Here is a strange problem: My app should be able to call the built in Maps in iOS (both 5.1 and 6). Turns out that it works just fine under iOS6 but not under iOS5.1. The maps in iOS6 is called and the directions from saddr to daddr is traced but when I am in iOS5 the maps app is called but just one pin is put at the daddr. For some unknown reason the initial coordinates (saddr) are not showing and no direction is traced.

这是我的代码:

addr = [NSString stringWithFormat: @"maps://saddr=%f,%f&daddr=%f,%f", newLocation.coordinate.latitude, newLocation.coordinate.longitude, oldLatitude, oldLongitude];
NSURL *url = [NSURL URLWithString:addr];
[[UIApplication sharedApplication] openURL:url];

我尝试将网址更改为http://maps.google.com/something但它调用Safari而不是内置的地图应用。我注意到变量正在正确传递给URL。

I have tried change the URL to "http://maps.google.com/something" but it calls Safari instead of built in Maps app. I have noticed that the variables are being passed properly to the URL.

任何想法?

提前致谢!

推荐答案

我遇到了类似的问题,我不得不创建一些条件操作系统代码来处理Google Maps应用程序这一事实已被删除。来自新的 MKMapItem Reference

I had a similar problem and I had to create some conditional OS code to deal with the fact that the Google Maps application has been removed. From the new MKMapItem Reference

//first create latitude longitude object
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude,longitude);

//create MKMapItem out of coordinates
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil];
MKMapItem* destination =  [[MKMapItem alloc] initWithPlacemark:placeMark];

if([destination respondsToSelector:@selector(openInMapsWithLaunchOptions:)])
{
    //using iOS6 native maps app
    [destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];        
} 
else
{
    //using iOS 5 which has the Google Maps application
    NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=Current+Location&daddr=%f,%f", latitude, longitude];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}

[placeMark release];
[destination release];

获取步行路线:


  1. 对于iOS 6地图 - 您可以设置 MKLaunchOptionsDirectionsModeWalking 而不是 MKLaunchOptionsDirectionsModeDriving

  2. 对于Google地图 - 将& dirflg = w 添加到网址。

  1. For iOS 6 maps - You can set MKLaunchOptionsDirectionsModeWalking instead of MKLaunchOptionsDirectionsModeDriving
  2. For Google maps - Add &dirflg=w to the url.

我认为最好在iOS6中使用openInMapsWithLaunchOptions,因为它可让您完全控制地图应用程序的响应方式。

I think it's better to use the openInMapsWithLaunchOptions in iOS6 because it gives you complete control over how the maps application will respond.

这篇关于从您的应用内部调用地图以获取路线 - iOS5 iOS6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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