gpt4 book ai didi

ios - map 应用程序不工作

转载 作者:行者123 更新时间:2023-11-28 22:23:23 25 4
gpt4 key购买 nike

看看下面的代码,它工作正常

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f", 23.0300, 72.5800, 22.3000, 70.7833];    
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[[UIApplication sharedApplication]openURL:url];

但它会在 safari 浏览器中打开 map 。

在那之后我尝试了下面的代码

NSString *urlString = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%f,%f&saddr=%f,%f", 23.0300, 72.5800, 22.3000, 70.7833];    
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[[UIApplication sharedApplication]openURL:url];

它按我的需要打开 map 应用程序,但没有给我路线的方向结果或与上面的谷歌地图相同的结果,我如何才能在 map 应用程序中获得作为第一个代码的结果?

请帮忙!!

最佳答案

Apple 的 map 没有与谷歌地图相同的 API,因此您的 URL 将无法使用。随着 iOS 6 苹果推出了 MKMapItem它允许开发人员与 maps.app 进行交互。

如果你想继续通过 http 使用 map ,那么你应该更改你的 url:

NSString *urlString = [NSString stringWithFormat:@"http://maps.apple.com/?daddr=%f,%f&saddr=%f,%f", 23.0300, 72.5800, 22.3000, 70.7833];    
NSString *escapedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url=[NSURL URLWithString:escapedString];
[[UIApplication sharedApplication]openURL:url];

Apple URL Scheme Reference 中所述你不应该添加 /maps/ 路径。

URLs that contain no path parameters or that contain specific map paths are opened in Safari and displayed there. For example, URLs based on the paths http://maps.apple.com/, http://maps.apple.com/maps, http://maps.apple.com/local, and http://maps.apple.com/m are all opened in Safari. To open a URL in the Maps app, the path must be of the form http://maps.apple.com/?q.

The rules for creating a valid map link are as follows:

  • The domain must be maps.apple.com.
  • The path cannot be /maps/*.
  • A parameter cannot be q=* if the value is a URL (so KML is not picked up).
  • The parameters cannot include view=text or dirflg=r

关于ios - map 应用程序不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19679633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com