Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
103
rated 0 times [  106] [ 3]  / answers: 1 / hits: 37035  / 14 Years ago, wed, march 2, 2011, 12:00:00

I created a map where a user inputs a zipcode and a radius (miles) and I want the map to center on the point created from the zipcode and only display (roughly) the area that would be within that radius. I am creating a Circle with the radius and trying to get the map to fit to that circle. Right now it centers correctly but the area being shown is way more than the radius given.



me.center_map = function(latlng, r)
{
// latlng is the point of the zipcode
var circ = new google.maps.Circle();
circ.setRadius(r * 1609.0);
circ.setCenter(latlng);
map.setCenter(latlng);
map.fitBounds(circ.getBounds());

// updates markers
google.maps.event.trigger(map,'dragend');
};


EDIT: Drew the circle that I am using. Ideally the map would be zoomed in to the area within the radius.



enter


More From » google-maps

 Answers
35

The call to fitBounds() will zoom to the smallest zoom level that fully contains the bounds. If you were to zoom in 1 more zoom level the radius would not be fully contained within the map.


[#93511] Monday, February 28, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
parker

Total Points: 259
Total Questions: 109
Total Answers: 97

Location: Zambia
Member since Thu, Jun 25, 2020
4 Years ago
;