I\'m using swift on iOS and using MKMapView. I\'ve been working on giving a user a from - to textfield and letting the user have a form of route between the from and to loca
Using google api to find directions between origin and destination.
Required parameters:
origin : lat + long current location or place ID .
destination : lat + long destination location or place ID .
Key: to create new google api key .
Optional parameters:
then convert points (inside overview_polyline) to list of CLLocationCoordinate2D using Polyline library https://github.com/raphaelmor/Polyline
Like this:
func convertPointToCoordinates() -> [CLLocationCoordinate2D]? {
let polyline = Polyline(encodedPolyline: overviewPolyline.points ?? "")
return polyline.coordinates
}
let coordinates = convertPointToCoordinates()
let polyLine = MKPolyline(coordinates: coordinates ?? [], count: (coordinates?.count ?? 0))
to add polyline on map view:
self.mapView.add(polyLine)
to focus on polyline region:
self.mapView.setVisibleMapRect(polyLine.boundingMapRect, edgePadding: UIEdgeInsets.init(top: 60, left: 60, bottom: 60, right: 60), animated: true)