Android:MapView绘制具有动态半径的圆(以米为单位)

发布于 2024-11-09 05:08:20 字数 885 浏览 6 评论 0原文

我的已知数据是我当前的位置(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮颜 2024-11-16 05:08:20

所以这有一个答案

我认为这个问题已经涵盖了

如何计算半径Android MapView 中的某个点周围?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文