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..:)
To remove a marker from the map, call the setMap() method passing null as the argument. marker. setMap(null);
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.
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:
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.
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.
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];
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 !
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