Question

I wanting to create an app which displays a map and on top of this map, the roads and points of interests will be painted as lines and ovals. These lines and ovals will have listeners attached to them so the user can drag them around or delete them.

I am using openstreetmaps with osmdroid however it seems to be exactly the same as Google Maps.

I was thinking of extending the OverlayItem class to represent a point of interest or a road. The Overlay class would be extended and contain an ArrayList of these extended OverlayItems.

The draw method of the Overlay class would be overridden and would paint all of the OverlayItem contained in the arraylist.

This Overlay class is then added to the MapView.

I am not sure if this would work because a lot of tutorials use an ItemizedOverlay. What exactly is this and should I be using it?

Thanks

Was it helpful?

Solution

An ItemizedOverlay is a class extending Overlay (as you want to do) and mostly completed (you still need to extend it and fill the specific parts) in order to add a list of Drawables to the map in specified Geopoints (using a list of OverlayItem). It also implements onTap() for the items added.

So bottom line, ItemizedOverlay is a pre-coded class aiming what seems to be your objective.

Limitations

It may not be the best solution for all your overlays ...

Examples where it would be better to use your own calss extending overlay:

  • If your POI requires a Drawable that needs to be rotated at runtime (i.e. an arrow pointing in a changing direction)
  • If you want to draw a route without markers
  • If you want to draw something that can't be easly made from a drawable

Regards.

OTHER TIPS

An ItemizedOverlay essentially does what you're talking about: it contains an itemized list of OverlayItem objects to draw.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top