Search code examples
androidlocationzoomingandroid-mapview

How to set a suitable zoom level on the 'mapview'?


        mMapController.animateTo(mAllSpots.get(0));
        mMapController.setCenter(mAllSpots.get(0));
        mMapController.setZoom(getZoomSize(mAllSpots));

There are 11 different points and I want to show them on the 'mapview',meanwhile,I want to see all of the 11 points on the 'mapview' .So what is the appropriate zoom level? Thanks.


Solution

  • mMapController.animateTo(mAllSpots.get(0));
    

    this 1 is for the point to means pan the map on specific/define location as given argument,

    mMapController.setCenter(mAllSpots.get(0));
    

    this 1 is for centered map based on the given argument as location value

    mMapController.setZoom(getZoomSize(mAllSpots));
    

    this 1 is for set the zoom level you need to use this method

    mMapController.zoomToSpan(latSpan, longSpan);
    

    here the latSpan and longSpan was define by maxlat-minlat and maxlng - minlng, first of all you need to find minlat,minlng and maxlat,maxlng and than sustract it whatever the value getting that you have to pass in this, this will work as zoom,animate, center together

    Edited

    you need to find to get from the mapview this will give you the maplatspan like suppose your points,

    p1 = 20.212323,68.803209;
    p2 = 20.222342,68.889898; 
    p3 = 22.212232,68.802093;
    

    now get the minlat,minlng and maxlat,maxlng and then substract it, this point was bound rect point as rectangle and find as center point of this rectangle

    minlat = 20.212232, minlng = 68.802093, maxlat = 22.212232, maxlng = 68.889898

    latspan = maxlat - minlat, lngspan = maxlng - minlng

    also you need to convert into the geopoint to multiply by with 1e6 like latspan*1e6 and lngspan*1e6 and now pass to the function