3

I'm using Google Maps iOS SDK and placed multiple markers with the marker info window opens when marker click. Now i want to add new marker which is not already plotted on map. I have list view with different places when user clicks on any place out side his local location, he will be jump to the selected location. Till this all working right but marker of place not displaying with error message:

Marker set as selectedMarker while not belonging to this map. Ignoring.

I'm re-plotting all the marker agin on selected location but its not working for me. Is there any way to plot single or multiple markers and set set selected marker default.

for (int i =0; i < [getdata count]; i++)
{
    LocationData *getlocation = [getdata objectAtIndex:i];
    CLLocationCoordinate2D position = CLLocationCoordinate2DMake(getlocation.lat, getlocation.longt);
    GMSMarker *marker = [GMSMarker markerWithPosition:position];
    marker.map = _mapView;
    marker.title = getlocation.name;
    marker.snippet = getlocation.disciption;
    marker.flat = YES;
    marker.icon = [UIImage imageNamed:img];
} 
  • check with this ans http://stackoverflow.com/a/21960210/4831524 – Antony Raphel Mar 04 '17 at 07:36
  • @AntonyRaphel marker not present on map i need to plot and selected at same time –  Mar 04 '17 at 07:55
  • When you plot the markers with for loop, it always select last marker which is plotted last. with this you can do the selection `[mapView setSelectedMarker:marker];` – Antony Raphel Mar 04 '17 at 08:20

1 Answers1

3

You can trigger method on location selection to plat single new marker with default selected on map:

For Obj c

GMSMarker *myMarkerAutomaticSnippet = [[GMSMarker alloc] init];
marker.position = <Your cordinates>;
marker.title = @“Title";
marker.snippet = @"Snippet";
marker.map = _mapView; 
[_mapView setSelectedMarker:marker];

For Swift 3.0

let myMarker = GMSMarker()
myMarker.position = <Your cordinates>
myMarker.title = "title"
myMarker.snippet = "snippet"
myMarker.map = _mapView    
_mapView.customMapView.selectedMarker = myMarker 
Sid Mhatre
  • 3,272
  • 1
  • 19
  • 38