Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove markers from google maps iOS

I am building an iOS app using storyboards and Google Maps. Using iOS6

My application features the split view navigation as seen in the facebook app

On my left view I am selecting an item in a list which has lat/long cords and showing it on my map on the following method

- (void)viewWillAppear:(BOOL)animated

I would like to remove all markers in this method before I add another one (so only one marker is on the map), is there a way to do this? Below is my code to add a marker to the mapView

Thanks in advance - Jon

- (void)loadView {     GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:poi.lat                                                             longitude:poi.lon                                                                  zoom:15];     mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];      mapView.myLocationEnabled = YES;     self.view = mapView;     mapView.mapType = kGMSTypeHybrid;      //Allows you to tap a marker and have camera pan to it     mapView.delegate = self; }  -(void)viewWillAppear:(BOOL)animated {     GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];     options.position = CLLocationCoordinate2DMake(poi.lat, poi.lon);     options.title =  poi.title;     options.snippet = poi.description;     options.icon =  [UIImage imageNamed:@"flag-red.png"];     [mapView addMarkerWithOptions:options];      [mapView animateToLocation:options.position];     [mapView animateToBearing:0];     [mapView animateToViewingAngle:0]; } 
like image 541
jchri853 Avatar asked Apr 17 '13 18:04

jchri853


People also ask

Can I turn off the markers in Google Maps?

Hover your cursor over the box and wait until more options appear. Click “More” to open the Map Details menu. Under “Map Type,” you'll see a checked box next to “Labels.” Uncheck it to remove all labels.

How do I remove pins from Google Maps?

If you want to remove the pin from Google Maps, simply right click on it and select "Remove this destination." Poof, it's gone.

How do I remove all markers from Maps?

You remove markers by using set_map(null) on the particular marker you want to clear, if you want to clear all then loop through using this function.


2 Answers

To remove all markers

mapView.clear() 

To remove a specific marker

myMarker.map = nil 
like image 110
Bassant Ashraf Avatar answered Sep 28 '22 12:09

Bassant Ashraf


To remove all markers simple do:

[self.mapView clear]; 
like image 38
jturolla Avatar answered Sep 28 '22 12:09

jturolla