我想从我的应用程序启动 Google map ,使用以下代码从我的位置导航到地址:
NSString *myAddress = [[NSString stringWithFormat:@"comgooglemaps://?daddr=Paris,France"] stringByAddingPercentEscapesUsingEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myAddress]];
当执行该代码时,如果谷歌地图尚未在后台打开,它会显示“无路线位置”,否则它会找到路线。 在这两种情况下,我有相同的起点(默认为“我的位置”)和终点。 如果我指定一个起点没问题,例如:
NSString *myAddress = [[NSString stringWithFormat:@"comgooglemaps://?saddr=Cannes,France&daddr=Paris,France"] stringByAddingPercentEscapesUsingEncoding];
是否有任何解决方案可以解决该问题?
最佳答案
检查此链接,可能会有帮助。 google map developer ios
用于获取从您当前位置出发的方向。 1-首先使用位置管理器获取您当前的位置。 2- 在 url 中添加它作为 saddr//这是你在第二行所做的(静态起始地址) 3- 然后添加您的目的地
试试这个
NSString *location=[NSString stringWithFormat:@"%f,%f",self.locationManager.location.coordinate.latitude.latitude,self.locationManager.location.coordinate.latitude.longitude];
if ([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:@"comgooglemaps://"]]) {
[[UIApplication sharedApplication] openURL:
//[NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
[NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?saddr=&daddr=%@&directionsmode=%@&views=satellite",location,mode]]
];
} else {
[[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Google Map app not found \n please install it." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Install", nil] show];
}
关于ios - "No routes found"在谷歌地图上首次启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21557974/