【问题标题】:How to Open Google Map Navigation Url with Direction and Voice in iOS?如何在 iOS 中使用方向和语音打开 Google 地图导航网址?
【发布时间】:2015-04-12 17:20:15
【问题描述】:

我是 iOS 的新手我想制作一个包含地图套件导航的应用程序。如果用户设备有谷歌地图应用程序,我想打开谷歌地图的导航 url。如果它不包含那么我想打开 Apple 地图在这里我写了一个类似 as 的代码

 -(IBAction)navigationButtonPressed:(id)sender
 {
if ([[UIApplication sharedApplication] canOpenURL:
     [NSURL URLWithString:@"comgooglemaps://"]])
{
    NSString *urlString=[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&zoom=14&views=traffic",self.latitude,self.longitude];
    [[UIApplication sharedApplication] openURL:
     [NSURL URLWithString:urlString]];
}
else
{
    NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/?ll=%f,%f",self.latitude,self.longitude];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]];
}
}

但是在这里我想打开谷歌地图或苹果地图,并在用户当前位置和选定位置之间逐个方向打开它怎么可能请给我解决方案。

【问题讨论】:

    标签: ios google-maps mapkit


    【解决方案1】:

    对于 Google 地图,您需要执行以下操作:-

    使用此方案来请求和显示两个位置之间的方向。您还可以指定运输方式。

    参数 saddr:设置路线搜索的起点。这可以是纬度、经度或查询格式的地址。如果是返回多个结果的查询字符串,则选择第一个结果。如果该值留空,则将使用用户的当前位置。 daddr:设置路线搜索的终点。具有与 saddr 相同的格式和行为。 方向方式:运输方式。可设置为:驾车、公交、骑自行车或步行。

    下面是一个示例 URL,用于显示 Google NYC 和 JFK 机场之间的公交路线:

    comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New +York&directionsmode=transit

    一些额外的例子如下:

    "comgooglemaps://?saddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA+94043&daddr=Google+Inc,+345+Spear+Street,+San+Francisco,+CA&center=37.422185 ,-122.083898&zoom=10"

    "comgooglemaps://?saddr=2025+Garcia+Ave,+Mountain+View,+CA,+USA&daddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA,+United+States&center= 37.423725,-122.0877&directionsmode=walking&zoom=17"

    参考

    https://developers.google.com/maps/documentation/ios/urlscheme

    对于 Apple Map,请执行以下操作:- 以下示例显示了您将用于提供旧金山之间的行车路线的字符串 和库比蒂诺:

    http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino

    参考:-

    https://developer.apple.com/library/iad/featuredarticles/iPhoneURLScheme_Reference/iPhoneURLScheme_Reference.pdf

    这对我有用,我在您的查询中看到的唯一问题是准确的经纬度值(那些看起来是纬度经度值,但作为十进制纬度经度值传递。

    示例 从唐尼到洛杉矶的路线 NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",34.0522300,-118.2436800,33.9400100,-118.1325700];

    但对于某些路线,它不起作用并显示路线不可用

    【讨论】:

    • 在这里我想传递纬度和经度,所以我写了一个像“NSString *string = [NSString stringWithFormat:@"http://maps.apple.com/?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",self.latitude,self.longitude,self.currentlatitude,self.currentlongitude]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:string]]; " ”这样的网址,但它对我不起作用。请给我解决方案。
    • 这对我有用,我在您的查询中看到的唯一问题是准确的纬度值(那些看起来是纬度经度值,但作为十进制纬度经度值传递)NSString *string = [ NSString stringWithFormat:@"maps.apple.com?daddr=%1.6f,%1.6f&saddr=%1.6f,%1.6f",34.0522300,-118.2436800,33.9400100,-118.1325700];我已经改进了我的答案,请检查上面的答案。
    【解决方案2】:

    您可以使用以下代码;它将出现带有放置注释的选定位置;并从谷歌应用程序你可以导航

    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
      NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"comgooglemaps://?center=%f,%f&q=%f,%f",mosqueLocation.latitude,mosqueLocation.longitude, mosqueLocation.latitude,mosqueLocation.longitude]];
      [[UIApplication sharedApplication] openURL:url];
    } else {
      NSLog(@"Can't use comgooglemaps://");
    }
    

    享受!!!!

    【讨论】:

      猜你喜欢
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 2013-01-08
      • 1970-01-01
      • 2012-12-31
      • 1970-01-01
      • 2012-12-03
      相关资源
      最近更新 更多