在地图上创建自定义覆盖自定义、在地、图上

2023-09-13 23:38:50 作者:我的帅气谁都别想拥有

我试图复制地图Android中的这一特点:

I am trying to replicate this feature of Maps in Android:

您可以看到在地图上,有一个圈,描绘了用户选择的范围。

You can see that on the map, there's a Circle depicting the range that the user has selected.

在我的应用程序,我也想一个牵引机驻留在圈内,它可以拖动重新定义半径的周长。

In my application, I'll also want a dragger to reside on the perimeter of the circle, which can be dragged to redefine radius.

如果有人能告诉我如何在地图中绘制自定义绘制覆盖和2D图形,我可以对我自己做其他事情。

If someone could tell me how to draw custom drawable overlays and 2D graphics over map, I can do other things on my own.

谢谢!

完整的应用程序可以在达到

The full application can be reached at this link

推荐答案

好吧,我试着做我自己的事情,并且把这种code,以获得上述效果:

Okay, I tried to do things on my Own, and put this code to get the above effect:

public class MarkerOverlay extends Overlay {

    Geocoder geoCoder = null;

    public MarkerOverlay() {
        super();
    }


    @Override
    public boolean onTap(GeoPoint geoPoint, MapView mapView){
        selectedLatitude = geoPoint.getLatitudeE6(); 
        selectedLongitude = geoPoint.getLongitudeE6();
        return super.onTap(geoPoint,mapView);
    }

    @Override
    public void draw(Canvas canvas, MapView mapV, boolean shadow){

        if(shadow){
            Projection projection = mapV.getProjection();
            Point pt = new Point();
            projection.toPixels(globalGeoPoint,pt);

            GeoPoint newGeos = new GeoPoint(selectedLat+(100),selectedLong); // adjust your radius accordingly
            Point pt2 = new Point();
            projection.toPixels(newGeos,pt2);
            float circleRadius = Math.abs(pt2.y-pt.y);

            Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);

            circlePaint.setColor(0x30000000);
            circlePaint.setStyle(Style.FILL_AND_STROKE);
            canvas.drawCircle((float)pt.x, (float)pt.y, circleRadius, circlePaint);

            circlePaint.setColor(0x99000000);
            circlePaint.setStyle(Style.STROKE);
            canvas.drawCircle((float)pt.x, (float)pt.y, circleRadius, circlePaint);

            Bitmap markerBitmap = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.pin);
            canvas.drawBitmap(markerBitmap,pt.x,pt.y-markerBitmap.getHeight(),null);

            super.draw(canvas,mapV,shadow);
        }
    }
}

这让我有以下作用:

使用的计算可能不是你想要的。 它只是为了演示。真实范围/距离计算需要采用承载过多的,并有一些特定的公式。 让我知道如果您对此有任何问题。

The calculation used may not be what you want. Its just for demonstration purposes. Real range/distance calculation requires the use of bearing too and has some specific formula. Let me know if you have any questions regarding this.