使用Objective-C在ios上开始使用多个目标进行导航

时间:2017-09-27 11:02:43

标签: ios objective-c google-maps url-scheme

以下代码无法在iPhone上打开Goog​​le地图应用,并且从一个点导航到另一个点,但是当我将同一个URL复制到桌面浏览器时,它会打开谷歌地图。

如何在Google地图应用中开始导航?

  

str = https://maps.google.com/maps/dir/?api=1&origin=18.606791,73.785611&destination=18.611997,73.971692&waypoints=18.606791,73.785611|18.611997,73.971692|18.465518,74.012204

if([[UIApplication sharedApplication] canOpenURL:
    [NSURL URLWithString:@"comgooglemaps://"]])
{
  [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

2 个答案:

答案 0 :(得分:0)

您可以从有关可用网址方案的Google文档开始。具体来说,有一个关于如何add navigation到您的应用的部分。

答案 1 :(得分:0)

试试这个..

NSString *escapedString = [strUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]];
    strUrl=[escapedString stringByReplacingOccurrencesOfString:@"%20" withString:@"+"];

if ([[UIApplication sharedApplication] canOpenURL:
         [NSURL URLWithString:@"comgooglemaps://"]])
    {
        [[UIApplication sharedApplication] openURL:
         [NSURL URLWithString:[@"comgooglemaps://?" stringByAppendingString:strUrl]]];
    }