Dav*_*idM 68 google-maps objective-c ios
在苹果开发者文档(链接现在是死的)解释说,如果你把在网页中的链接,然后单击它,而在iPhone上,也作为标准配置提供与iPhone将推出谷歌地图应用程序中使用移动Safari浏览器.
如何在我自己的原生iPhone应用程序中启动具有特定地址的相同Google地图应用程序(即通过Mobile Safari不是网页),就像在联系人中点击地址启动地图一样?
注意:这仅适用于设备本身.不在模拟器中.
Ada*_*ght 65
对于iOS 5.1.1及更低版本,请使用openURL方法UIApplication.它将执行正常的iPhone魔法URL重新解释.所以
[someUIApplication openURL:[NSURL URLWithString:@"http://maps.google.com/maps?q=London"]]
Run Code Online (Sandbox Code Playgroud)
应该调用Google地图应用.
从iOS 6开始,您将调用Apple自己的地图应用程序.为此,MKMapItem请使用要显示的位置配置对象,然后将其发送给openInMapsWithLaunchOptions消息.要从当前位置开始,请尝试:
[[MKMapItem mapItemForCurrentLocation] openInMapsWithLaunchOptions:nil];
Run Code Online (Sandbox Code Playgroud)
您需要将此链接与MapKit相关联(我相信它会提示进行位置访问).
Dav*_*idM 31
究竟.您需要实现此目的的代码是这样的:
UIApplication *app = [UIApplication sharedApplication];
[app openURL:[NSURL URLWithString: @"http://maps.google.com/maps?q=London"]];
Run Code Online (Sandbox Code Playgroud)
因为根据文档,除非您调用sharedApplication,否则UIApplication仅在Application Delegate中可用.
Jan*_*les 29
要在特定坐标下打开Google地图,请尝试以下代码:
NSString *latlong = @"-56.568545,1.256281";
NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?ll=%@",
[latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Run Code Online (Sandbox Code Playgroud)
您可以使用CoreLocation中的当前位置替换latlong字符串.
您还可以使用("z")标志指定缩放级别.值为1-19.这是一个例子:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@" http://maps.google.com/maps?z=8 "]];
Mic*_*aks 18
现在还有App Store Google Maps应用程序,记录在https://developers.google.com/maps/documentation/ios/urlscheme
所以你首先检查它是否已安装:
[[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]];
然后你就可以有条件地替换http://maps.google.com/maps?q=用comgooglemaps://?q=.
Har*_*ove 13
以下是地图链接的Apple URL方案参考:http://developer.apple.com/iphone/library/featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html
创建有效地图链接的规则如下:
- 域必须是google.com,子域必须是maps或ditu.
- 如果查询包含site作为键,local作为值,则路径必须是/,/ maps,/ local或/ m.
- 路径不能是/ maps/*.
- 必须支持所有参数.有关支持的参数列表**,请参阅表1.
- 如果值是URL(因此未拾取KML),则参数不能为q =*.
- 参数不能包含view = text或dirflg = r.
**有关支持的参数列表,请参阅上面的链接.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
</array>
Run Code Online (Sandbox Code Playgroud)
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps:"]]) {
NSString *urlString = [NSString stringWithFormat:@"comgooglemaps://?ll=%@,%@",destinationLatitude,destinationLongitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
} else {
NSString *string = [NSString stringWithFormat:@"http://maps.google.com/maps?ll=%@,%@",destinationLatitude,destinationLongitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
Run Code Online (Sandbox Code Playgroud)
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "comgooglemaps:")!) {
var urlString = "comgooglemaps://?ll=\(destinationLatitude),\(destinationLongitude)"
UIApplication.sharedApplication().openURL(NSURL(string: urlString)!)
}
else {
var string = "http://maps.google.com/maps?ll=\(destinationLatitude),\(destinationLongitude)"
UIApplication.sharedApplication().openURL(NSURL(string: string)!)
}
Run Code Online (Sandbox Code Playgroud)
if UIApplication.shared.canOpenURL(URL(string: "comgooglemaps:")!) {
var urlString = "comgooglemaps://?ll=\(destinationLatitude),\(destinationLongitude)"
UIApplication.shared.openURL(URL(string: urlString)!)
}
else {
var string = "http://maps.google.com/maps?ll=\(destinationLatitude),\(destinationLongitude)"
UIApplication.shared.openURL(URL(string: string)!)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
95022 次 |
| 最近记录: |