Google Maps user-editable polygon with fixed number of points in Android?

前端 未结 2 1978
攒了一身酷
攒了一身酷 2020-12-21 17:20

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

相关标签:
2条回答
  • 2020-12-21 17:57

    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());
      }
    }
    
    0 讨论(0)
  • 2020-12-21 18:02

    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.

    0 讨论(0)
提交回复
热议问题