Implementing Google Map: how set auto zoom and center?

Associate
Joined
6 Jan 2006
Posts
1,024
Location
Midlands
Hi,
I am currently implementing a google map into my site.

The pointers on the map is dynamically plotted.

Is there a way to set the zoom level and center depending the spread of the pointers?

Thanks
 
i believe not, although i havent done a huge amount of complex google maps stuff recently.

if you are plotting the points dynamiclly couldnt you work out the centre and rough required zoom level manually
 
Yea looks like i have to.

I was hoping there was something in the api i can use.

Thank you for replying!
 
You can set boundaries in googlemaps based on minimum and maximum longitude and latitude. Thats instead of using zoom and center.

Heres some example code from I site I did with a similar purpose:

http://www.mytripbook.com/trip/show/545/paying-respects-a-trip-to-belgium-and-france

Code:
var minLat=49.1810862;
var minLng=-1.5333333;
var maxLat=53.9833333;
var maxLng=3.2250023;
					
botLeft = new GLatLng(minLat, minLng);
topRight = new GLatLng(maxLat, maxLng);

bounds = new GLatLngBounds(botLeft, topRight);
map.setCenter(new GLatLng(((maxLat + minLat) / 2.0),((maxLng + minLng) / 2.0)),map.getBoundsZoomLevel(bounds));

You just need to use PHP to get the minimum/maximums from your array of points (assuming its coming out of a database)
 
Last edited:
Back
Top Bottom