Android:MapView绘制具有动态半径的圆(以米为单位)
我的已知数据是我当前的位置(GeoPoint)和以米为单位的半径。我想根据地图投影和半径在当前位置周围绘制圆圈。 我的地图视图叠加层确实覆盖了绘制方法,例如
@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);
}
此代码的问题是 radiusPixel
太小了。我假设问题出在 metersToEquatorPixels
方法中,该方法采用米为单位的参数并计算大约。如果该米位于赤道上,则为像素。我说得对吗? 但我想计算我的半径需要多少像素,而不仅仅是当我站在赤道上时。是否有适合此类工作的内置功能,还是我必须手动完成?
问候
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以这有一个答案
我认为这个问题已经涵盖了
So this has an answer
I think it's covered by this question