Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a MapView that I'm displaying a "useful radius" (think accuracy of coordinate) in. Using MapView's Projection's metersToEquatorPixels, which is admittedly just for equatorial distance) isn't giving me an accurate enough distance (in pixels). How would you compute this if you wanted to display a circle around your coordinate, given radius?

like image 252
Jeremy Logan Avatar asked Jan 16 '10 10:01

Jeremy Logan


1 Answers

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))));         
}
like image 56
Jeremy Logan Avatar answered Oct 17 '22 23:10

Jeremy Logan