Android: MapView circle with dynamic radius (in meters)

My known data is my current location (GeoPoint) and radius in meters. I want to draw a circle around my current location based on the map projection and radius. My overlay of map view overrides the drawing method like

@Override public void draw(Canvas canvas, MapView mapView, boolean shadow) { Projection projection = mapView.getProjection(); GeoPoint myLocationGeoPoint = getLocationGeoPointFromSomeSource(); Point myPoint = new Point(); projection.toPixels(myLocationGeoPoint, myPoint); int radiusPixel = (int) projection.metersToEquatorPixels(getRadiusInMetersFromSomeSource()); canvas.drawCircle(myPoint.x, myPoint.y, radiusPixel, mPaintStroke); canvas.drawCircle(myPoint.x, myPoint.y, radiusPixel, mPaintFill); super.draw(canvas, mapView, shadow); } 

The problem with this code is that radiusPixel too small. I assume the problem is with the metersToEquatorPixels method, which takes a parameter in meters and calculates approx. pixels if these meters are at the equator. I'm right? But I want to calculate how many pixels my radius occupies, not only if I stand at the equator. Is there a built-in function for this kind of work or do I need to do this manually?

Hi

+6
source share
1 answer

So this one has an answer

I think that covered this issue.

How to calculate radius around a point in Android MapView?

+6
source

Source: https://habr.com/ru/post/888777/


All Articles