gpt4 book ai didi

ios - Swift 3中的Google Maps API指南

转载 作者:行者123 更新时间:2023-12-01 20:00:09 26 4
gpt4 key购买 nike

当我开始使用Swift 3时,在使用Google Maps API指南构建路线时遇到了问题。

我的路线有几个航点,在Swift 3中,URL:

https://maps.googleapis.com/maps/api/directions/json?origin=48.4843822562792,35.0635632500052&destination=48.4893899423081,35.0640017911792&waypoints=48.4833428800255,35.0710221379995|48.4887622031403,35.0573639944196&key=AIzaSyAWpBT3uxovKLqdWIiwa29a4AcgtspAA1k

由于“|”而无效。有什么建议么?

最佳答案

对于那些想使用路线googlemaps api的人,您必须在参数数组中发送航点。因此,管道不再引起问题。

    var wayPointsString = "optimize:true"
if waypointsForRequest.count > 0 {
for location in waypointsForRequest {
wayPointsString = "\(wayPointsString)|\(location.coordinate.latitude),\(location.coordinate.longitude)"
}
}
let parameters : [String : String] = ["key" : self.directionsApikey, "sensor" : "false", "mode" : "driving", "alternatives" : "true", "origin" : "\(origin.coordinate.latitude),\(origin.coordinate.longitude)", "destination" : "\(destination.coordinate.latitude),\(destination.coordinate.longitude)", "waypoints" : wayPointsString]
let url = URL(string: "https://maps.googleapis.com/maps/api/directions/json?")

Alamofire.request(url!, method:.get, parameters: parameters)
.validate(contentType: ["application/json"])
.responseJSON { response in
if response.value != nil {
let json = JSON(response.value!)

}
}

有趣的答案在这里: https://stackoverflow.com/a/40126476/3173405

关于ios - Swift 3中的Google Maps API指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40176177/

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