6

My known data are my current location (GeoPoint) and radius in meters. I want to draw circle around my current location based on map projection and radius. My map view overlay does override draw 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);
}

Problem of this code is that radiusPixel is far too small. I assume that the problem is in metersToEquatorPixels method which takes parameter in meters and calculates approx. pixels if that meters are on equator. Am I right? But I want to calculate how many pixels does my radius takes not only if I stand on equator. Is there any build-in function for that kind of job or do I have to do it by hand?

Regards

zmeda
  • 2,909
  • 9
  • 36
  • 56
  • googlemaps and osmdroid can implement methods in different manners, it's always good to make which mapping platform you are using. – tony gil Aug 21 '17 at 18:15

1 Answers1

6

So this has an answer

I think it's covered by this question

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

Community
  • 1
  • 1