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
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());
}
}
I think you're using the tools you have a little inefficiently. My recommendation would be to store an array of markers, and use markerTag to store the index of your point, so in drawPolygon
for (int i = 0; i < coordinates.size(); i++) {
markers[i].setTag(i); //Associate a marker with a point
}
Then, when you move the marker, you would replace the co-ordinate at that point like so:
points[marker.getTag().toInt()] = marker.getTag().getPosition();
Sorry this is so vague. I use kotlin, so I've probably gotten some of the syntax wrong, too.