开发者

Android: MapView draw circle with dynamic radius (in meters)

开发者 https://www.devze.com 2023-03-08 02:19 出处:网络
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 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 v开发者_运维百科oid 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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消