Search code examples
google-mapsjava-memidp

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.


Solution

  • 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