Ama*_*lam 7 android android-sdk-2.1 android-maps
我想在Android中复制Google地图的这个功能:

您可以在地图上看到,圆圈描绘了用户选择的范围.
在我的应用程序中,我还希望拖动器驻留在圆的周边,可以拖动以重新定义半径.
如果有人能告诉我如何在地图上绘制自定义可绘制叠加和2D图形,我可以自己做其他事情.
谢谢!
可以通过此链接访问完整的应用程序
Ama*_*lam 18
好吧,我试着在我自己做的事情,并把这个代码,以获得上述效果:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这让我有以下效果:

使用的计算可能不是您想要的.
它仅用于演示目的.
实际距离/距离计算也需要使用轴承并具有一些特定的公式.
如果您对此有任何疑问,请与我们联系.
| 归档时间: |
|
| 查看次数: |
19589 次 |
| 最近记录: |