Reputation: 3
I am building program that displays location of many people. How can I set the Center so it shows all the locations?
This is my code but I need to zoom out to see other locations
gMaps = new GoogleMaps();
map = gMaps.createMap(getWidth(), getHeight(), GoogleStaticMap.FORMAT_PNG);
map.setHandler(this);
map.setCenter(new GoogleMapsCoordinates(24.71167 ,46.72417));
Upvotes: 0
Views: 709
Reputation: 10974
This can be achieved by using the fitBounds() method. Check out the Google Maps v3 API reference.
Small example:
//set viewport
var viewport = new google.maps.LatLngBounds();
viewport.extend(p1);
viewport.extend(p2);
//center map using active markers
map.fitBounds(viewport);
In that example, p1 and p2 are coordinates (lat,lng).
Upvotes: 1