Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove particular GMSMarker from GMSMapview using Google Map sdk in ios

I am integrating google maps sdk. Its all work fine. But how to remove particular Marker(Pin Point) when second will appear.(I am not using Mapkit)

I want the following:

If i tap on map then one marker pin is generate at that location now if i tap on another location on map then two pins are displayed but i want to remove the old marker pin.

I also use,

[self.mapView clear];

But it was clear all other marker points from GMSMapview.

Following is the code to add pin on Map:

            GMSMapView *mapView;
            GMSMarker *currLocMarker = [[GMSMarker alloc] init];
            currLocMarker.map  = nil;
            [currLocMarker setTitle:NSLocalizedString(@"current_location_title", nil)];
            currLocMarker.icon = [UIImage imageNamed:@"pin_fetch_location.png"];
            currLocMarker.position = CLLocationCoordinate2DMake(pCoordinate.latitude, pCoordinate.longitude);
            currLocMarker.map = self.mapView;

Please help me to solve out this stuff..!!

Thanks in advance..:)

like image 538
jigs Avatar asked Jan 18 '14 06:01

jigs


People also ask

How do I remove a marker from Google Maps API?

To remove a marker from the map, call the setMap() method passing null as the argument. marker. setMap(null);

What is a marker in GMS?

A marker is an icon placed at a particular point on the map's surface. A marker's icon is drawn oriented against the device's screen rather than the map's surface; i.e., it will not necessarily change orientation due to map rotations, tilting, or zooming. Inherits GMSOverlay. Convenience constructor for a default marker.

How do I connect GMS mapview to Interface Builder?

Select the map view in Interface Builder, hold down the Ctrl key and drag a line from the map view to MapViewController.swift. A popup will appear; set the connection type to Outlet and the name to mapView. Keep the Type as GMSMapView, and click Connect:

How do I turn a UIView into a gmsmapview?

To turn this simple UIView into a GMSMapView, select the view you just added and open the Identity inspector by selecting the third tab from the left in the Utilities toolbar. Change the view’s Class to GMSMapView, as shown in the screenshot below: Next, you’ll need to add some constraints to make the map fill the entire screen.

How do I change the camera of a gmsmapview?

Build a GMSCameraPosition that presents bounds with padding. The camera will have a zero bearing and tilt (i.e., facing north and looking directly at the Earth). This takes the frame and padding of this GMSMapView into account. If the bounds is invalid this method will return a nil camera. Changes the camera according to update.


2 Answers

To remove a particular pin from GMSMapView keep reference of pin (if there are multiple then use array) then use this code

currLocMarker.map  = nil;

To remove all things including pins poly lines from GMSMapView use this code

[ _mapView clear];
like image 162
Spydy Avatar answered Oct 13 '22 23:10

Spydy


I made like this:

GMSMarker *myMarker;

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        if (myMarker) {
            myMarker.map = nil;
            myMarker = nil;
        }
        myMarker = [[GMSMarker alloc] init];
        myMarker.position = CLLocationCoordinate2DMake(coordinate.latitude, coordinate.longitude);
        myMarker.title = @"title";
        myMarker.map = mapView_;
    }];
}

and worked well for me !

like image 38
3ddy Avatar answered Oct 14 '22 01:10

3ddy