gpt4 book ai didi

iOS)从谷歌路线API的两个坐标中获取不到路线

转载 作者:行者123 更新时间:2023-11-30 12:36:45 46 4
gpt4 key购买 nike

我正在尝试获取原点坐标和目标坐标之间的路线。

我引用了stackoverflow .

所以我的代码如下:

let url = "https://maps.googleapis.com/maps/api/directions/json?origin=37.496375,126.9546903&destination=37.48121,126.9505233&mode=walking&key=MY_KEY"
Alamofire.request(url).responseJSON
{ response in
print(response.request) // original URL request
print(response.response) // HTTP URL response
print(response.data) // server data
print(response.result) // result of response serialization

let json = JSON(data: response.data!)
let routes = json["routes"].arrayValue

for route in routes
{
let routeOverviewPolyline = route["overview_polyline"].dictionary
let points = routeOverviewPolyline?["points"]?.stringValue
let path = GMSPath.init(fromEncodedPath: points!)
let polyline = GMSPolyline.init(path: path)
polyline.map = self.mapView
}
}

但结果是,response.data 如下:

{
"status" : "ZERO_RESULTS",
"available_travel_modes" :
[
"TRANSIT"
],
"geocoded_waypoints" : [
{},
{}],"routes" : []}

关于这个问题,我搜索了一下,发现可能是坐标无法转换成地址导致的。

但我确实检查了两个坐标都被“CLGeocoder”(reverseGeocodeLocation)转换为正确的地址。

最后,我确实在“maps.google.com”上检查了相同的坐标地址,并向我显示了路线。

如何解决这个问题?

最佳答案

available_travel_modes contains an array of available travel modes. This field is returned when a request specifies a travel mode and gets no results. The array contains the available travel modes in the countries of the given set of waypoints.

您的回复返回为

"available_travel_modes":["TRANSIT"]

所以尝试将 mode=walking 更改为 &mode=transit

关于iOS)从谷歌路线API的两个坐标中获取不到路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42762994/

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