【发布时间】:2018-06-20 10:31:41
【问题描述】:
我想使用起始位置和结束位置在多个点之间绘制路线,我正在关注一些示例和此链接以获取 json 以获取航点 https://directionsdebug.firebaseapp.com/?origin=place_id%3AChIJ59dGBGBwTDkRlQsbxkBkqNw&destination=place_id%3AChIJ0TGAdgh6TDkRTFcRvOIXIOY&mode=driving&waypoints=Kotri%2C%20Jamshoro%2C%20Sindh%2C%20Pakistan&alternatives=true
这是我的代码,我没有使用链接获得所有积分,请指导我如何使用起点和航点
func drawpath() {
let url = "https://maps.googleapis.com/maps/api/directions/json?origin=place_id%3AChIJ59dGBGBwTDkRlQsbxkBkqNw&destination=place_id%3AChIJ0TGAdgh6TDkRTFcRvOIXIOY&mode=driving&waypoints=Kotri%2C%20Jamshoro%2C%20Sindh%2C%20Pakistan&alternatives=true&key=AIzaSyCct09KdoyIc3VV5Bziw5Tk9MF0RhWXTNE"
Alamofire.request(url).responseJSON { response in
print(response.request as Any) // original URL request
print(response.response as Any) // HTTP URL response
print(response.data as Any) // server data
print(response.result as Any) // result of response serialization
let json = try! JSON(data: response.data!)
let routes = json["routes"][0]["legs"][0]["steps"].arrayValue
print("route is\(routes)")
// print route using Polyline
for route in routes
{
let routeOverviewPolyline = route["polyline"].dictionary
let points = routeOverviewPolyline?["points"]?.stringValue
print("ppoint\(String(describing: points))")
print("routeOverviewPolyline\(String(describing: routeOverviewPolyline))")
let path = GMSPath.init(fromEncodedPath: points!)
let polyline = GMSPolyline.init(path: path)
polyline.strokeWidth = 4
polyline.strokeColor = UIColor.red
polyline.map = self.mapview
}
}
【问题讨论】:
-
不,兄弟,这个例子是路线上的动画,我不想要这个,我想使用多个航点绘制路线
标签: ios swift google-maps direction google-directions-api