0
我使用Google Map v2。我想從地圖中選擇一些區域。我想提供用戶在屏幕上移動他的手指時的功能,並且我想繪製一個圓以從地圖中選擇區域。所以請告訴我該怎麼做android如何在地圖上繪製cricle
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_free_draw);
fram_map = (FrameLayout) findViewById(R.id.fram_map);
fram_map.addView(new DrawView(FreeDrawActivity.this));
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
map.getUiSettings().setScrollGesturesEnabled(false);
cameraPosition = getIntent().getExtras().getParcelable("position");
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
// Zoom in, animating the camera.
// map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
val = new ArrayList<LatLng>();
fram_map.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
int x_co = Math.round(x);
int y_co = Math.round(y);
projection = map.getProjection();
Point x_y_points = new Point(x_co, y_co);
LatLng latLng = map.getProjection().fromScreenLocation(
x_y_points);
latitude = latLng.latitude;
longitude = latLng.longitude;
int eventaction = event.getAction();
switch (eventaction) {
case MotionEvent.ACTION_DOWN:
// finger touches the screen
val.add(new LatLng(latitude, longitude));
case MotionEvent.ACTION_MOVE:
// finger moves on the screen
val.add(new LatLng(latitude, longitude));
case MotionEvent.ACTION_UP:
// finger leaves the screen
Draw_Map();
break;
}
if (Is_MAP_Moveable == true) {
return true;
} else {
return false;
}
}
});
}
public void Draw_Map() {
PolygonOptions rectOptions = new PolygonOptions();
rectOptions.addAll(val);
rectOptions.strokeColor(Color.BLUE);
rectOptions.strokeWidth(7);
rectOptions.fillColor(Color.CYAN);
Polygon polygon = map.addPolygon(rectOptions);
}
這段代碼用手指移動繪製一個多邊形。但我想提請圈
http://android-er.blogspot.in/2013/02/draw-tranparent-circle-for-google-maps.html – Riser 2014-12-03 10:39:57
http://stackoverflow.com/questions/6029529/draw-circle-of-certain-radius-on-map-view-in-android – Riser 2014-12-03 10:40:26
這將點擊一個圓圈。我不想在點擊上繪製圓圈。我想在手指上畫圈。 – 2014-12-03 10:49:44