在Android中具有固定点数的Google Maps用户可编辑多边形? [英] Google Maps user-editable polygon with fixed number of points in Android?
问题描述
我正在使用Google Map多边形标记,我已经预定义了纬度/经度数组,并且需要设置多边形区域,这对我来说很好,但是当我拖动标记多边形线不变时,它应该具有拖动标记时会发生变化.
I am working on Google Map polygon marker, I have predefined lat/long array, and need to set polygon area, It is working fine for me, but when I drag the marker polygon line doesn't change, it should have to be change as I drag the marker.
这是我的问题,我将放一张图片来说明它.
Here is my problem, I'll put a picture to illustrate it easier.
这是代码:
myMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
@Override
public void onMarkerDragStart(Marker marker) {
}
@Override
public void onMarkerDrag(Marker marker) {
updateMarkerLocation(marker);
drawPolygon(coordinates);
}
private void updateMarkerLocation(Marker marker) {
LatLng latLng = (LatLng) marker.getTag();
int position = coordinates.indexOf(latLng);
if (position >= 0) {
coordinates.set(position, marker.getPosition());
marker.setTag(marker.getPosition());
}
}
@Override
public void onMarkerDragEnd(Marker marker) {
}
});
}
private void drawPolygon(List<LatLng> coordinates) {
if (polygon != null) {
polygon.remove();
}
PolygonOptions polygonOptions = new PolygonOptions();
polygonOptions.fillColor(Color.GREEN);
polygonOptions.strokeColor(Color.GREEN);
polygonOptions.strokeWidth(3);
polygonOptions.addAll(coordinates);
polygon = myMap.addPolygon(polygonOptions);
}
像上面的图像一样,我的标记移动了,但没有形成多边形.
like above image my marker move but not make polygon.
坐标包含来自sqlite的多边形坐标
推荐答案
似乎您正在使用Marker
标记存储多边形点的最后显示的坐标(LatLng
).要显示的坐标存储在coordinates
是吗?
It looks like you're using the Marker
tag to store the last displayed coordinate (LatLng
) of the polygon point. The coordinates to be displayed are stored in coordinates
yes?
如果是这样,那么我猜你的代码应该是:
If so then I'm guessing your code should be:
private void updateMarkerLocation(Marker marker) {
LatLng latLng = (LatLng) marker.getTag();
int position = coordinates.indexOf(latLng);
if (position >= 0) {
coordinates.set(position, marker.getPosition());
marker.setTag(marker.getPosition());
}
}
这篇关于在Android中具有固定点数的Google Maps用户可编辑多边形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!