How to change 1 meter to pixel distance?

后端 未结 5 2173
一个人的身影
一个人的身影 2020-12-25 09:50

When I develop an Android map application, I want to draw a circle on the map whose radius is 1 meter. As you known, I can\'t draw 1 meter directly, I should convert 1 meter

5条回答
  •  自闭症患者
    2020-12-25 10:08

    Take a look at the Projection object in the api. It has a method on it called metersToEquatorPixels(). Given the description in the api, it might only be accurate along the equator, but I thought it was worth mentioning in case accuracy wasn't an issue for you.

    Here's the way to use this inside the draw method of your overlay, given the radius in meters and the latitude and longitude of where you want to draw the circle:

    Projection projection = mapView.getProjection();
    Point center = projection.toPixels(new GeoPoint(yourLat * E6, yourLong * E6), null);
    float radius = projection.metersToEquatorPixels(radiusInMeters);
    canvas.draw(center.x, center.y, radius, new Paint());
    

提交回复
热议问题