I am trying to fit a polyline in the google map view. The polyline was acquired through overview_polyline in the google maps directions api.
Wondering how I would be able to convert an encoded polyline into something that can be worked with. I need to fit the polyline in the map view. All i have found out to do is fit the bounds to show all markers but not showcase the entire polyline.
func fitAllMarkers()
{
var bounds = GMSCoordinateBounds()
for marker in markers
{
bounds = bounds.includingCoordinate(marker.position)
}
googleMapView.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds))
}
You can zoom the map according the route or line displayed in the mapview. So that your route is displayed with in the mapView bounds.
Here path is GMSPath of the route and mapView is GmsMapView.
Though the question has an accepted answer,
Still one point which has not been discussed.
GMSPolyLine has a property ".path" which can used to bound the map with the complete polyline itself.
With this approach, It'll do the job for sure.
Coz it has Done for me..
Hope it Helps..
For Swift 2.0 Google Maps, to make your map view fit the polyline of the route you are drawing: