Click here to Skip to main content
15,886,664 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 :

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

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


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?
Posted

1 solution

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

C#
if (place.geometry.viewport) {
           map.fitBounds(place.geometry.viewport);
       } else {
           map.setCenter(place.geometry.location);
           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