我通过正确传递经度和纬度参数来获取当前位置的MapView
。但我想在MapView
图像上绘制像自由手(即名字或线条等等)的颜料。从那我想要用户在该画上的MapView
图像的总图像。
我怎么能这样做?
当用户将其路径发送给另一个用户时,如下所示...
答案 0 :(得分:2)
使用叠加层。 See this example Overlays
以下是示例代码:
public class overlayGeoPoints extends Overlay {
private GeoPoint geoPoint;
private int radius = 20;
@Override
public boolean onTap(GeoPoint geoPoint, MapView mapView){
this.geoPoint = geoPoint;
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
// put your logic here to draw on the overlay
// ie draw a circle
Projection projection = mapView.getProjection();
Point point = new Point();
projection.toPixels(geoPoint, point);
int px = point.x;
int py = point.y;
Paint paint = new Paint(paintSecondary.ANTI_ALIAS_FLAG);
hl.setColor(intColor);
canvas.drawCircle(px, py, radius, paint);
canvas.save();
}
}
只需将此叠加层添加到地图中即可。
修改强>
这是一步一步(通用):
创建地图对象(地图)后
// get a handle to the map overlays
List<Overlay> overlays = mapView.getOverlays();
// reset overlays as necessary
//overlays.clear();
// create your custom overly class
overlayGeoPoints olay = new overlayGeoPoints();
// append overlay to map overlays
overlays.add(olay);
// tell the map object to redraw
mapView.postInvalidate();
答案 1 :(得分:1)
如果我正确地理解了你的问题,你想捕捉那些徘徊的动作,然后在地图上显示。
<强>步骤:强>
onTouchEvent()
以获取用户点击并移动手指的位置(x,y),将它们转换为Geopoint并将地理点添加到Path对象。请致电invalidate()
让地图重新显示。onDraw()
以使用canvas.drawPath()
答案 2 :(得分:0)
// This file is MapViewDemoActivity.java
import android.os.Bundle;
import android.view.View;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
public class MapViewDemoActivity extends MapActivity {
private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapview);
mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true); //display zoom controls
}
@Override
protected boolean isLocationDisplayed() {
return false;
}
这一生对所有http://n3vrax.wordpress.com/2011/08/13/drawing-overlays-on-android-map-view/
都很有用