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]; }
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.
If you want to remove the pin from Google Maps, simply right click on it and select "Remove this destination." Poof, it's gone.
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.
To remove all markers
mapView.clear()
To remove a specific marker
myMarker.map = nil
To remove all markers simple do:
[self.mapView clear];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With