How to compute a radius around a point in an Android MapView?

爷,独闯天下 提交于 2019-11-28 18:26:59

So, Google Maps uses a Mercator projection. This means that the further you get from the equator the more distorted the distances become. According to this discussion, the proper way to convert for distances is something like:

public static int metersToRadius(float meters, MapView map, double latitude) {
    return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ Math.cos(Math.toRadians(latitude))));         
}
Mohan Kumar
mMap.addCircle(
    new CircleOptions().center(
        new LatLng(
            bounds.getCenter().latitude, 
            bounds.getCenter().longitude
        )
    )
    .radius(50000)
    .strokeWidth(0f)
    .fillColor(0x550000FF)
);
projection.toPixels(GeoP, pt);
float radius = projection.metersToEquatorPixels(50);

Try this and see... i used it on my MapRadius and it seems to be working

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