代码之家  ›  专栏  ›  技术社区  ›  reza_khalafi

如何在谷歌地图上用url和起点和终点之间的参数创建路线?

  •  0
  • reza_khalafi  · 技术社区  · 8 年前

    我想开一家 网址 并自动在两点之间建立路线。我在中找不到正确的url和参数 谷歌地图 文件

    2 回复  |  直到 8 年前
        1
  •  1
  •   reza_khalafi    8 年前

    你可以这样做 斯威夫特4 :

            let url = URL(string: "https://maps.google.com")
            if (UIApplication.shared.canOpenURL(url!))
            {
                let originLat:String = String(locationManager.location!.coordinate.latitude)
                let originLong:String = String(locationManager.location!.coordinate.longitude)
                let destLat:String = String(locationObj.latitude)
                let destLong:String = String(locationObj.longitude)
    
                let openUrlString:String = String(format:"https://www.google.com/maps/dir/?api=1&origin=%@,%@&destination=%@,%@&travelmode=driving",originLat,originLong,destLat,destLong)
    
                print("openUrlString is : \(openUrlString)")
    
    
                let openUrl = URL(string: openUrlString)
                UIApplication.shared.open(openUrl!, options: [:]) { (res:Bool) in
    
                }
            }
    
        2
  •  0
  •   Bijender Singh Shekhawat    8 年前

    斯威夫特3号和斯威夫特4号

    let apiKey = "https://www.google.com/maps/dir/" + userCurrentLocation.coordinate.latitude + "," + userCurrentLocation.coordinate.longitude + "/" + nextCurrentLocation.coordinate.latitude + "," + nextCurrentLocation.coordinate.longitude
    
        var url = URL(string: apikey)
    

    用于目标c

       NSString *apikey = [NSString stringWithFormat:@"https://www.google.co.in/maps/dir/%f,%f/%f,%f",userCurrentLocation.coordinate.latitude,userCurrentLocation.coordinate.longitude,nextCurrentLocation.coordinate.latitude,nextCurrentLocation.coordinate.longitude;
    
    NSURL *url = [NSURL URLWithString:apikey];
    
    [[UIApplication sharedApplication] openURL:url];