How to show an annotation on a map

2812
4
Jump to solution
09-27-2015 10:50 AM
SyedMahmud
New Contributor

Now that I have loaded a map in my app, I need to show a marker annotation for a location. Here is the code I'm using but nothing is showing on the map:

CLLocation *location = [[CLLocation alloc] initWithLatitude:douLat longitude:douLon];

  AGSPoint *markerPoint = [AGSPoint pointWithLocation:location];

 

  AGSGraphicsLayer* myGraphicsLayer = [AGSGraphicsLayer graphicsLayer];

  [self.ibMapView addMapLayer:myGraphicsLayer withName:@"Graphic Layer"];

  AGSPictureMarkerSymbol *markerSymbol = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:@"existing_project_icon.png"];

  AGSGraphic* myGraphic = [AGSGraphic graphicWithGeometry:markerPoint

   symbol:markerSymbol

   attributes:nil];

 

  // Add the graphic to the Graphics layer

  [myGraphicsLayer addGraphic:myGraphic];

  [self.ibMapView.callout showCalloutAtPoint:markerPoint forFeature:myGraphic layer:myGraphicsLayer animated:YES];

Please help.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
GagandeepSingh
Occasional Contributor II

I just replaced the (duoLat, duoLon) in your code with (0, 0) and it worked for me. Can you see the graphic on the map?

View solution in original post

0 Kudos
4 Replies
MC2
by
New Contributor

- Did you set your viewController to be the delegate for callouts (`AGSCalloutDelegate`)?

This is initially `nil` & needs to be set or else annotations won't appear. You can then implement the delegate methods to control what the annotation displays.

Displaying a callout—ArcGIS Runtime SDK for iOS | ArcGIS for Developers

- Not sure it's relevant, but you call `showCalloutAtPoint...` immediately after adding the graphic.

Does `myGraphic` appear? If not, maybe refresh the layer or map before calling this method?

0 Kudos
GagandeepSingh
Occasional Contributor II

Where are you calling the `showCalloutAtPoint` method from? Try doing it from the `mapViewDidLoad` delegate.

0 Kudos
SyedMahmud
New Contributor

Thanks for responding. I couldn't make much progress. Here is another way asking the same question:

Given the CLLocation *location, how can I draw an annotation on the map?

Any code samples would be highly appreciated.

Thanks.

0 Kudos
GagandeepSingh
Occasional Contributor II

I just replaced the (duoLat, duoLon) in your code with (0, 0) and it worked for me. Can you see the graphic on the map?

0 Kudos