gpt4 book ai didi

ios - 在 iPhone 的 safari 中通过应用程序打开谷歌地图

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

我想通过我的应用程序打开谷歌地图以获得源地址等于我当前位置的方向,目标地址是我的字符串。我使用了下面的代码,我能够打开应用程序但无法得到方向。

 NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=My+Location&daddr=%@", [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

通过使用这行代码,我可以打开应用程序,但 map 没有显示当前位置,目标地址在那里。

我也通过传递当前位置的纬度和经度来使用它,但这也将当前位置的纬度和经度都显示为 0.0000。

  NSString* url = [NSString stringWithFormat: @"http://maps.google.com/maps?saddr=%1.6f,%1.6f&daddr=%@",
coordinate.latitude, coordinate.longitude,
[address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];

最佳答案

这对我有用:

NSString *coordinateString1 = [NSString stringWithFormat:@"%f,%f", coordinate1.latitude, coordinate1.longitude];
NSString *coordinateString2 = [NSString stringWithFormat:@"%f,%f", coordinate2.latitude, coordinate2.longitude];
NSURL *URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@&daddr=%@",coordinateString1,coordinateString2]];
[[UIApplication sharedApplication] openURL: URL];

关于ios - 在 iPhone 的 safari 中通过应用程序打开谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21659587/

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