11

Does exist any way to remove GMSPolygons from GMSMapView?

It does not seem to exist a property of GMSMapView containing them (as GMSPlolyLines), should I clear the map and render all again?

thanks

joseprupi
  • 317
  • 4
  • 13
  • Check my code for do it in this topic. http://stackoverflow.com/questions/25102778/remove-gmspolyline-from-gmsmapview/30364285#30364285 – Linh Nguyen May 21 '15 at 04:01

3 Answers3

18

When you create the GMSPolygon you set its map property to add it to the map. To remove it from the map, set its map property to nil. This means you need to keep your own record of the polygons which you've added to the map, which you want to be able to remove later.

For example mySavedPolygon.map = nil

kuzdu
  • 7,124
  • 1
  • 51
  • 69
Saxon Druce
  • 17,406
  • 5
  • 50
  • 71
  • thanks saxon, works for me. once I've seen the solution I've also seen it's obvious, but I'm new at ios and google maps ios sdk – joseprupi Jul 15 '13 at 11:48
6

From google maps document

  • clear Clears all markup that has been added to the map, including markers, polylines and ground overlays.

So you just use

[mapView clear];

This should clear the polygons.

Jing
  • 1,935
  • 3
  • 17
  • 26
  • @Bangalore please refer to the newest google maps documentation. This answer is almost 3 year old, and may not work in the latest SDK. – Jing Mar 21 '16 at 02:23
  • checkout my issue, i think [map clear ] is the correct answer but some how its not working for me http://stackoverflow.com/questions/36114766/gmsmapview-clear-method-is-not-removing-gmspolygon-ios/36122085#36122085 – Bangalore Mar 21 '16 at 03:24
  • @Bangalore You management solve the problem ? I am use the viewMap.clear and viewMap.map = nil but this no work. – Cristian Mora Feb 01 '17 at 15:19
2

This has been updated, has I am using the clear function, and was looking for a way to keep the polygons while using this.

I've just confirmed against the Google Maps API Reference.

Clears all markup that has been added to the map, including markers, polylines and ground overlays.

https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_map_view.html#a28e6b8aeb7c8dc9025dc001f2a5d2c9b