Setting Viewport on Google Maps when sending several addresses -
i have code send several addresses google maps. however, since i'm doing a series of geocodings, how can make viewport @ least center , zoom correctly on group?
function dobatchgeocodeandsearch() { $('#loading').css('visibility', 'visible'); var lines = $('#styled').val().split('\n'); for(var = 0;i < lines.length;i++){ geocoder.geocode( { 'address': lines[i]}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.fitbounds(results[0].geometry.viewport); // map.setcenter(bounds.getcenter(), // map.getboundszoomlevel(bounds)); map.setcenter(results[0].geometry.location);
remove map.setcenter call. last call map.fitbounds show markers, if there 1 marker, zoom in close though, may want handle specially.
var bounds = new google.maps.latlngbounds(); for(var = 0;i < lines.length;i++){ geocoder.geocode( { 'address': lines[i]}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { bounds.extend(results[0].geometry.location); map.fitbounds(bounds);
Comments
Post a Comment