【问题标题】:Polyline in google map for IOS swiftIOS swift的谷歌地图中的折线
【发布时间】:2019-08-26 18:00:49
【问题描述】:

我一直在研究谷歌折线功能。我已经初始化了 URL,并且我使用了 alamofire 请求。带有 URL 的所有内容都可以正常工作,但我无法画线,并且显示为无效 URL。

我已经附上了我尝试过的代码。

let urlString = "https://maps.googleapis.com/maps/api/directions/json?origin=\(pickupcordinates)&destination=\(dropCoordinates)&mode=driving&key=AIzaSyDJUX9uBiZivQGlAu1KTUC1kcmaiAnI270"

Alamofire.request(urlString,method: .get, parameters: nil,encoding: JSONEncoding.default, headers: nil).responseJSON {
    response in
    switch response.result {
    case .success:
        print(response)
        break
    case .failure(let error):

        print(error)
    }
}

invalidURL(url: "https://maps.googleapis.com/maps/api/directions/json?origin=13.03589205752495,80.25411217280107&destination=13.0277895999, 80.22673778239999&mode=driving&key=AIzaSyDJUX9uBiZivQGlAu1KTUC1kcmaiAnI270")

以上是我的控制台响应错误

我想画一条从源到目的地的折线。

【问题讨论】:

  • 显示您在控制台中遇到的错误
  • 在控制台中获取无效 URL
  • 你真的想要截图
  • 您的网址似乎有效。刚刚检查过。
  • @KarthickTM...是的,表明这一点

标签: ios swift


【解决方案1】:

我正在使用这种方式尝试一下。可以帮到你。

func drawPath(source: CLLocationCoordinate2D, destination: CLLocationCoordinate2D){

        let orgin = "\(source.latitude),\(source.longitude)"
        let destin = "\(destination.latitude),\(destination.longitude)"
        let url = "https://maps.googleapis.com/maps/api/directions/json?origin=\(orgin)&destination=\(destin)&mode=driving"

        Alamofire.request(url).responseJSON { response in

            switch response.result {
             case .success:
                let json = JSON(data: response.data!)
                let routes = json["routes"].arrayValue
                print(response)

             break
             case .failure(let error):
               print(error)
            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-02
    • 2014-07-07
    相关资源
    最近更新 更多