简体   繁体   中英

Draw a polygon on mapview + android

I want to draw a polygon on the map view. It is like, i have an number of GeoPoints and then using those geopoints, i want to draw a polygon with n vertices.

thanks!!

Update:

thanks to freza, now i know how to draw a overlay.

There is an another function under overlay class : public boolean onTap(GeoPoint p, MapView mapView) . Now what i want is when user tap on any overlay, i want to change the image of the overlay.

For example, initially i have drawn a simple green circle for displaying overlay. So now when user taps on that green overlay: i want to change the color to red or draw a new bitmap in place if green circle. How can i do this?

This can help you. code follows:

          private void changeMarkers(int noteIndex) {
    for (int i = 0; i < noteOverlays.size(); i++) {
        if (i == noteIndex || noteIndex == -1) {
            Drawable selectedMarker = getResources().getDrawable(
                    R.drawable.note_in_map);
            int selectedMarkerWidth = selectedMarker.getIntrinsicWidth();
            int selectedMarkerHeight = selectedMarker.getIntrinsicHeight();
            selectedMarker.setBounds(-selectedMarkerWidth / 2,
                    -selectedMarkerHeight, selectedMarkerWidth / 2, 0);         noteOverlays.getItem(i).setMarker(selectedMarker);
        } else {
            Drawable unselectedMarker = getResources().getDrawable(
                    R.drawable.note_in_map_notselected);
            int nonSelectedMarkerWidth = unselectedMarker
                    .getIntrinsicWidth();
            int nonSelectedMarkerHeight = unselectedMarker
                    .getIntrinsicHeight();
            unselectedMarker
                    .setBounds(-nonSelectedMarkerWidth / 2,
                            -nonSelectedMarkerHeight,
                            nonSelectedMarkerWidth / 2, 0);
            noteOverlays.getItem(i).setMarker(unselectedMarker);
        }
    }
    mapView.invalidate();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM