I'm working in a Java Me application that uses google static maps. The problem is that I need to get the zoom and center that fits all markers, and I need to add some labels in some coordinates on the map. How can I do this? I need a function in the server or in the midlet to get this parameters, I can't use javascript.
Asked
Active
Viewed 4,031 times
3 Answers
7
I have had the same problem. Don't use "&zoom=xx" in your url, the map will auto-fit for all your markers!

Luca N.
- 71
- 1
- 2
-
For me does not works. The `&zoom=xx` parameter needs to be on the url. – robe007 May 23 '19 at 15:01
7
You don't need to calculate it on your own.
When you supply markers, usually the map will have a viewport to show all markers.
To modify the viewport use the visible-parameter.
Referring to the comments:
Pseudo-Code for calculating the center from a couple of Points:
latitude: (maxLatOfAllPoints+minLatOfAllPoints)/2
longitude:(maxLngOfAllPoints+minLngOfAllPoints)/2
-
Thanks for your answer. The problem is that I need to get the center in the mobile application to be able to paint some labels in the map. – Laura Isabel Mar 05 '12 at 20:53
-
When you know the positions of the markers it needs a little bit mathematics to calculate the center(see above) – Dr.Molle Mar 06 '12 at 06:45
-
1I came here searching for this, documentation URL should now be: https://developers.google.com/maps/documentation/static-maps/intro?hl=en#Viewports – tomvo Dec 18 '15 at 08:19
-1
Define bounds object
bounds = new google.maps.LatLngBounds();
When you create and place marker on the map extend bondes with marker position.
bounds.extend(mPosition);
where
mPosition
is a googlenew google.maps.LatLng(0,0)
object, the same that you use during marker creation.at the end ot you can create a link for click or just run.
map.fitBounds(bounds);
That is it.

Sergey Romanov
- 2,949
- 4
- 23
- 38
-
OP is asking for a static map, not the interactive one that this is for – locrizak Mar 11 '13 at 19:48