overlay - Google Maps API: Calculate Center/Zoom of Polyline -


i have overlay dynamically generated user data, need know how find center of overlay.

currently, using first coordinates overlay, not represent center of overlay. therefore when load map, not centered on overlay.

does have method centering map on overlay, calculating center, not hard coding it?

var latlng = new google.maps.latlng(38.269239, -122.276010);     var myoptions = {         zoom: 15,//calculate somehow?         center: latlng,// calculate value array of coordinates?         maptypeid: google.maps.maptypeid.hybrid     }; 

if have list of coordinates, can loop on them , add them latlngbounds object. here example v3 api, concept in v2 similar:

var bounds = new google.maps.latlngbounds(); (var = 0; < coordinates.length; i++) {   bounds.extend(coordinates[i]); } 

after that, can center with:

bounds.getcenter(); 

or alternatively, can call map.fitbounds() directly, center map around center of bounds , adjust zoom, whole bounds fit view port.

map.fitbounds(bounds); 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -