javascript - Is there a way to tell Google map to zoom out centered on a marker and show a calculated bounding box? -
when visitor clicks site shows streetview @ location. when exit picture code fetches nearest 2 marker coordinates (from mongodb) , zooms map out include calculated bounding box.
i have map remain centered on marker visited , zoom out enough show complete bounding box. user keep track of they've been.
click image calculate bounding box
the marker image 1 on left. can see bounding box centered.
i've had read through nothing seemed obvious me. google api v3 have method this?
/**** collect data restful service code gets nearest 2 markers , calculates zoom set map include them in view. ****/ bounds = new google.maps.latlngbounds(); bounds.extend(new google.maps.latlng( data.locs.lat, data.locs.lng )); nearest = {}; $.ajax({ type: "get", datatype: "json", data: { lat : data.locs.lat, //the marker viewing lng : data.locs.lng}, async: false, url: "php/restful.get.nearest.markers.php", success: function (data) { nearest = data; } }); $.each(nearest, function () { bounds.extend(new google.maps.latlng( this.locs.lat, this.locs.lng )); }); /**** end collect data restful service ****/ map.fitbounds(bounds); new google.maps.rectangle({ bounds: bounds, map: map, fillcolor: "#000000", fillopacity: 0.2, strokeweight: 0 });
this not easiest way can start.
look @ google maps api mapoptions. see property called zoom, third bottom, controls map zoom(obviously).
then there 2 methods getzoom , setzoom in map's methods can used programmatically control zoom level of map.
you have experiment these , of course setcenter should not big issue.
experiment , find zoom level covers, in terms of distance, calculate bounding box covers , set zoom level , center accordingly.
Comments
Post a Comment