gpt4 book ai didi

android - 在 map 上创建自定义叠加层

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:12:17 24 4
gpt4 key购买 nike

我正在尝试在 Android 中复制 map 的这个功能: Custom Map Overlay

你可以看到在 map 上,有一个圆圈描绘了用户选择的范围。

在我的应用程序中,我还希望在圆周上放置一个拖动器,可以拖动它以重新定义半径。

如果有人能告诉我如何在 map 上绘制自定义可绘制叠加层和 2D 图形,我可以自己做其他事情。

谢谢!

完整的申请可以通过 this link 获得

最佳答案

好吧,我试着自己做一些事情,并把这段代码得到上面的效果:

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);
}
}
}

这让我有以下效果:

Effect on Map

使用的计算可能不是你想要的。
这只是为了演示目的。
真正的范围/距离计算也需要使用方位并且有一些特定的公式。
如果您对此有任何疑问,请告诉我。

关于android - 在 map 上创建自定义叠加层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4428730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com