Ara*_*and 22 iphone google-maps coordinates mapkit
我正在使用UIMapView在iPhone上显示位置.我想从当前位置到感兴趣的位置做一个方向,我认为不可能使用MapKit(但如果是请通知)所以我将打开Google Maps应用程序或safari来显示它.
我可以通过指定从(当前位置)到坐标(感兴趣的位置)的坐标来实现这一点,我有这些经度和纬度.或者我必须使用街道地址?
如果我必须使用街道地址,我可以从纬度和经度获得它们.
Ado*_*lfo 74
是的,使用MapKit是不可能的.您可以尝试形成一个Google地图网址请求,其中包含您将在Google地图应用中按指示打开的当前位置和目标位置.
这是一个示例网址:
http://maps.google.com/?saddr=34.052222,-118.243611&daddr=37.322778,-122.031944
以下是您在代码中实现此功能的方法:
CLLocationCoordinate2D start = { 34.052222, -118.243611 };
CLLocationCoordinate2D destination = { 37.322778, -122.031944 };
NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
start.latitude, start.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
Run Code Online (Sandbox Code Playgroud)
Vis*_*ngh 10
在Swift 3中使用谷歌和苹果地图的轰鸣声代码 -
if UIApplication.shared.canOpenURL(URL(string: "comgooglemaps://")!)
{
let urlString = "http://maps.google.com/?daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&directionsmode=driving"
// use bellow line for specific source location
//let urlString = "http://maps.google.com/?saddr=\(sourceLocation.latitude),\(sourceLocation.longitude)&daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&directionsmode=driving"
UIApplication.shared.openURL(URL(string: urlString)!)
}
else
{
//let urlString = "http://maps.apple.com/maps?saddr=\(sourceLocation.latitude),\(sourceLocation.longitude)&daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&dirflg=d"
let urlString = "http://maps.apple.com/maps?daddr=\(destinationLocation.latitude),\(destinationLocation.longitude)&dirflg=d"
UIApplication.shared.openURL(URL(string: urlString)!)
}
Run Code Online (Sandbox Code Playgroud)
这是可能的。使用MKMapView获取您在手机上点击的位置坐标,并使用这两个坐标从谷歌网络服务请求KML文件,解析KML文件(开发人员站点中的示例应用程序 KML 查看器)并显示路线。 ..
谢谢