我正在尝试在Google地图上绘制手绘形状,到目前为止,我已经成功地绘制了折线和多边形,感谢@Chintan Khetiya在 在Android中的Google地图V2上绘制自由手多边形和在地图上绘制路径中的回复。但是,当我尝试像下面的图片一样绘制多边形时,"polygonOptions.fillColor(color)"无法正常工作。我尝试将点转换为两个多边形,但也没有用。有人可以提供建议或分享任何提示或更好的解决方案来使用Google地图多边形绘制填充颜色的自由手形状吗?
这是我如何绘制多边形
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 = mMap.getProjection();
Point x_y_points = new Point(x_co, y_co);
LatLng latLng = mMap.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() {
rectOptions = new PolygonOptions();
rectOptions.addAll(val);
rectOptions.strokeColor(Color.BLUE);
rectOptions.strokeWidth(7);
rectOptions.fillColor(Color.CYAN);
polygon = mMap.addPolygon(rectOptions);
}
在"Zillow房地产Android应用程序"中也使用了类似的功能。