Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get zoom and center to fit all markers in a google static map

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.

like image 455
Laura Isabel Avatar asked Oct 14 '25 19:10

Laura Isabel


2 Answers

I have had the same problem. Don't use "&zoom=xx" in your url, the map will auto-fit for all your markers!

like image 53
Luca N. Avatar answered Oct 17 '25 12:10

Luca N.


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

like image 40
Dr.Molle Avatar answered Oct 17 '25 11:10

Dr.Molle