• iOS App通過URL調用谷歌地圖導航


    1、給iPhone安裝google map app,因為之後會使用這個程序進行導航

    2、在自己的App中需要進行導航的地方,加入下列代碼

    if ([[UIApplication sharedApplication] canOpenURL:
         [NSURL URLWithString:@"comgooglemaps://"]]) {
      [[UIApplication sharedApplication] openURL:
       [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
    } else {
      NSLog(@"Can't use comgooglemaps://");
    }

    這裏的if主要就是判斷手機中是否有google map app.如果有就將url參數傳入google mao app.

    舉例:

    comgooglemaps://?center=46.414382,10.013988&mapmode=streetview
    center=46.414382,10.013988為中心點顯示地圖

    3、導航的參數

    實現導航功能的URL會有三個參數,saddr,daddr,directionsmode,以下是google官方提供的介紹。

    • saddr: Sets the starting point for directions searches. This can be a latitude,longitude or a query formatted address. If it is a query string that returns more than one result, the first result will be selected. If the value is left blank, then the user’s current location will be used.
    • daddr: Sets the end point for directions searches. Has the same format and behavior as saddr.
    • directionsmode: Method of transportation. Can be set to: driving, transit, bicycling or walking.

    下面以例子來介紹該如何使用

    1、官方例子,直接進行兩個點的導航
    comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=transit
    2、通過經緯度實現兩個點的導航
    url = [NSString stringWithFormat:@"comgooglemaps://?saddr=37.782652,-122.410126&daddr=%lf,%lf&directionsmode=driving", targetLocation.latitude, targetLocation.longitude];
    3、以手機所在位置為起始點進行導航
    url = [NSString stringWithFormat:@"comgooglemaps://?daddr=%lf,%lf&directionsmode=driving", targetLocation.latitude, targetLocation.longitude];
  • 相关阅读:
    网易云课堂Dubbo学习笔记
    Java的native方法
    java中三种for循环之间的对比
    java中的匿名内部类小结
    三重DEC加密在java中的实现
    CoreException: Could not get the value for parameter compilerId for plugin execution default-compile Maven项目pom文件报错,插件引用不到
    安装plsql developer
    Eclipse安装插件的“最好方法”:dropins文件夹的妙用
    linux项目部署常用命令
    Linux学习笔记
  • 原文地址:https://www.cnblogs.com/scaptain/p/4209141.html
Copyright © 2020-2023  润新知