2

I am trying to add a custom overlay to a Google Maps map in my program, but I'm unable to find the method to do so when using fragments.

All the examples and guides I've been able to found are using MapView, and the overlays can be added as simply as myMapView.getOverlays().add(myOverlay).

I can't however find a similar method when working with a fragment instead of MapView. I have a handle to the GoogleMap, which does not seem to contain .getOverlays(), and I am not having that much success with the fragment itself either.

So, can I, and/or where can I find a similar method for adding a overlay to a MapFragment instead of MapView?

varesa
  • 2,399
  • 7
  • 26
  • 45

1 Answers1

3

In google maps v2 its not called an overlay, its called a polygon. You add one to the map by calling GoogleMap.addPolygon(PolygonOptions option) Where GoogleMap is replaced by the name of your GoogleMap object. Heres some info on PolyOptions for you So that way you just add the points, no matter how many points there are and then it makes a polygon based on those points. Or for nonbuildings and just lines, use the PolyLines Option

Heres the Googlemap API for your reference.

Hope this helps

EDIT :

Drawing a circle is a little bit more intricate since it involves anti aliasing and a little song and dance.

For your convenience I found this StackOverflow answer which includes some code on how to get it done.

Community
  • 1
  • 1
dannyRods
  • 552
  • 6
  • 23
  • I know version 1 had overlays, and you can add rects and stuff like that, but this is just easier. Google probably makes sure that the LatLng points connect properly to form a building, or a park, or what have you – dannyRods Feb 14 '13 at 22:04
  • So if I, for example wanted a circle, I would have to manually construct it from vertices? – varesa Feb 15 '13 at 07:45
  • 1
    Circles are slightly more complicated. I made an edit of my answer to reflect that – dannyRods Feb 15 '13 at 20:26