Ios &引用;“未找到任何路线”;谷歌地图首次发布
我想从我的应用程序启动Google Maps,以从我的位置导航到具有以下代码的地址:Ios &引用;“未找到任何路线”;谷歌地图首次发布,ios,objective-c,google-maps,Ios,Objective C,Google Maps,我想从我的应用程序启动Google Maps,以从我的位置导航到具有以下代码的地址: NSString *myAddress = [[NSString stringWithFormat:@"comgooglemaps://?daddr=Paris,France"] stringByAddingPercentEscapesUsingEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:myAddress
NSString *myAddress = [[NSString stringWithFormat:@"comgooglemaps://?daddr=Paris,France"] stringByAddingPercentEscapesUsingEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myAddress]];
当该代码被执行时,如果谷歌地图还没有在后台打开,它会显示“No routes location”,否则它会找到一条路线。
在这两种情况下,我有相同的起点(默认情况下为“我的位置”)和终点。
如果我指定一个起点,则没有问题,例如:
NSString *myAddress = [[NSString stringWithFormat:@"comgooglemaps://?saddr=Cannes,France&daddr=Paris,France"] stringByAddingPercentEscapesUsingEncoding];
是否有任何解决方案可以解决此问题?请查看此链接,可能会有所帮助。 用于从当前位置获取方向。 1-首先使用location manager获取当前位置。 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];
}
不幸的是,我已经阅读了该链接,并尝试使用其他参数,如directionsmode=driving,但结果相同。如果我指定了一个起始点,但我更喜欢使用谷歌地图的默认“我的位置”,则可以使用。我想我只需调用以下url:“comgooglemaps://?q=Paris,France”,用户只需点击导航按钮即可。感谢您的帮助我想您的url字符串[NSURL URLWithString:[NSString stringWithFormat:@“comgooglemaps:/?SADD=%@&daddr=%@&directionsmode=%@&views=satellite”,location,destination,mode]]中有一个错误,因为我从代码中复制了它。别担心,它在我这边起作用。