我正在使用Google Map v2。我想从地图中选择一些区域。我想在用户在屏幕上移动手指时提供功能,我想画一个圆圈从地图中选择区域。怎么做?
@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);
}
此代码用手指移动绘制多边形。但我想绘制圆圈。
答案 0 :(得分:0)
尝试这样,
public void Draw_Map(LatLng point) {
CircleOptions circleOptions = new CircleOptions()
.center(point) //set center
.radius(500) //set radius in meters
.fillColor(Color.TRANSPARENT) //default
.strokeColor(Color.BLUE)
.strokeWidth(5);
Circle myCircle = myMap.addCircle(circleOptions);
}