views:

92

answers:

2

Hey guys, I have the Uncertain number of GeoPoint, i want to display them all on the google maps. I don't know how to do it. thank you!

A: 

Use itemized overlay.

Note: this is generally very slow for a large amount of points (more than a few hundreds). Large lists require some other optimizations, such as finding a way to show only points inside the currently displayed part of the map, etc. But for short lists, it works fine.

amitlicht
A: 
    private void fitPoints(List<GeoPoint> points) {
    // set min and max for two points
    int nwLat = -90 * 1000000;
    int nwLng = 180 * 1000000;
    int seLat = 90 * 1000000;
    int seLng = -180 * 1000000;
    // find bounding lats and lngs
    for (GeoPoint point : points) {
        nwLat = Math.max(nwLat, point.getLatitudeE6());
        nwLng = Math.min(nwLng, point.getLongitudeE6());
        seLat = Math.min(seLat, point.getLatitudeE6());
        seLng = Math.max(seLng, point.getLongitudeE6());
    }
    GeoPoint center = new GeoPoint((nwLat + seLat) / 2, (nwLng + seLng) / 2);
    // add padding in each direction
    int spanLatDelta = (int) (Math.abs(nwLat - seLat) * 1.1);
    int spanLngDelta = (int) (Math.abs(seLng - nwLng) * 1.1);

    // fit map to points
    mapController.animateTo(center);
    mapController.zoomToSpan(spanLatDelta, spanLngDelta);
}
BahaiResearch.com