How to scale a MapView from Pixels to Meters

送分小仙女□ 提交于 2019-12-11 03:46:51

问题


I'm making an Android application which uses Google Maps API, and I want to scale a MapView to X_pixels:X_meters.

For example, 5 pixels of the MapView in my screen, 20 meters on reality.

Is that possible?

Thx


回答1:


Use the following code:

    int nPixles = 5; //number of pixels
    GeoPoint g0 = mapview.getProjection().fromPixels(0, mapview.getHeight()/2);
    GeoPoint g1 = mapview.getProjection().fromPixels(nPixles, mapview.getHeight()/2);
    float[] results = new float[1];
    Location.distanceBetween(g0.getLatitudeE6()/1E6, g0.getLongitudeE6()/1E6, g1.getLatitudeE6(), g1.getLongitudeE6()/1E6, results);
    float distanceInMeters = results[0];

This calculates distance in meters for latitude level at screen center. Because earth is spheric distance vary from bottom to the top of screen. This is mostly noticed with low zoom levels.

Regards.



来源:https://stackoverflow.com/questions/13635551/how-to-scale-a-mapview-from-pixels-to-meters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!