gpt4 book ai didi

ios - 适用于 IOS swift 的谷歌地图中的折线

转载 作者:行者123 更新时间:2023-11-29 05:30:22 25 4
gpt4 key购买 nike

我一直在研究谷歌折线功能。我已经初始化了 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")

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

我想绘制一条从源到目的地的多段线。

最佳答案

我正在使用这个方法,你可以尝试一下。可能对你有帮助。

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)
}
}
}

关于ios - 适用于 IOS swift 的谷歌地图中的折线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57652512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com