ios - "No routes found"在谷歌地图上首次启动

标签 ios objective-c google-maps

我想从我的应用程序启动 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/

相关文章:

ios - 了解将数据从第二个 View Controller 传回主视图 Controller 时的机制

ios - 开始在后台播放声音 IOS 7

objective-c - 如何在 iOS 中将整数转换为 id

javascript - 等待使用 getCurrentPosition 达到准确度阈值

angular - 引用错误 : "google is not defined"

iphone - iOS Bluetooth LE peripheralManager didReceiveWriteRequests 的例子在哪里

UIKit 的 textColor 的 iOS13 白色问题

ios - 如何在 Swift 3.0 中通过 Segue 从子类传递变量和对象

javascript - 将参数传递给创建谷歌地图的函数不起作用

objective-c - 在phonegap上使用sharekit进行xcode中的重复错误(但对于phonegap-plugin则不如此)