Guest User

Untitled

a guest
Dec 10th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. let prefTravel = "driving"
  2. let apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  3.  
  4. let url = URL(string: "https://maps.googleapis.com/maps/api/directions/json?origin=(origin)&destination=(destination)&mode=(prefTravel)&key=(apiKey)")
  5.  
  6. Alamofire.request(url!).responseJSON { response in
  7.  
  8. print(response.request as Any) // original URL request
  9. print(response.response as Any) // HTTP URL response
  10. print(response.data as Any) // server data
  11. print(response.result as Any) // result of response serialization
  12. do {
  13. let json = try JSON(data: response.data!)
  14. let routes = json["routes"].arrayValue
  15. // print route using Polyline
  16. for route in routes
  17. {
  18. let routeOverviewPolyline = route["overview_polyline"].dictionary
  19. let points = routeOverviewPolyline?["points"]?.stringValue
  20. let path = GMSPath.init(fromEncodedPath: points!)
  21. let polyline = GMSPolyline.init(path: path)
  22. polyline.strokeWidth = 4
  23. polyline.strokeColor = UIColor.red
  24. polyline.map = self.mapView
  25. }
  26. } catch let err {
  27. print(err)
  28. }
  29. }
  30. }```
Add Comment
Please, Sign In to add comment