Click here to Skip to main content
15,790,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello all,
I've used the Google maps geometry library to store a route on a map. Now I want to load that route, therefore I use the following code :

var encoded = $("#ContestRouteInfo").val();
map.config.routingPoly = new google.maps.Polyline({
    strokeColor: '#fc4c02',
    strokeOpacity: 0.75,

map.config.path = google.maps.geometry.encoding.decodePath(encoded);

This runs fine, the route is perfectly drawn on the map, however after loading I want to zoom the map and (re)set the center of the map so the route is visible. How can I determine the perfect zoom level and center of the map?

1 solution

i think you have to use this code inside your "google.maps.event.addListener" function

if (place.geometry.viewport) {
       } else {
           map.setZoom(14); // you can set perfect zoom level here.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900