AGSSimpleMarkerSymbol not showing up where expected

4085
1
02-09-2015 06:04 PM
MatthewSullivan
New Contributor

I'm completely new to ArcGIS for iOS. It's extremely interesting but I'm not understanding something. I'm creating an AGSGraphicsLayer and adding an AGSSimpleMarkerSymbol to it. The symbol is showing up on my map but not where I expected it. I'm wondering if this is somehow related to the dread AGSSpatialReference, which I don't fully understand at this point.

 

What I'm doing is zooming in on the user's location, using an AGSEnvelope determined from the user's location. This works fine. I'm then attempting to drop a red-coloured pin quite close to the blue pin that shows my location. Here's the first part:

 

    AGSLocation* location = self.mapView.locationDisplay.location;

    double lon = location.point.x;

    double lat = location.point.y;

    double extent = 0.01;

   

    AGSEnvelope* env = [AGSEnvelope envelopeWithXmin:lon - extent

                                                ymin:lat - extent

                                                xmax:lon + extent

                                                ymax:lat + extent

                                    spatialReference:[AGSSpatialReference wgs84SpatialReference]];

 

    [self.mapView zoomToEnvelope:env animated:YES];

    NSLog(@"zoomToUsersLocation: {%.6f, %.6f}", lon, lat);

 

I'll skip the bit of code where I create the symbol because it works fine, but when I attempt to place the symbol onto the graphics layer I created earlier, it shows up far away from where I expected. (I live on the west Coast of Canada, and that's where the blue pin from the above code shows I am, while the red symbol ends up on the west coast of Africa! 🙂

 

AGSPoint* nearUserPt = [AGSPoint pointWithX:lon + .001

                                                                          y:lat + .001

                                                    spatialReference:self.mapView.spatialReference];

 

    NSLog(@"nearUserPt: {%.6f, %.6f}", nearUserPt.x, nearUserPt.y);

    AGSGraphic* graphic = [AGSGraphic graphicWithGeometry:nearUserPt

                                                   symbol:symbol

                                                attributes:nil

                                     infoTemplateDelegate:nil];

    AGSGraphicsLayer* graphicsLayer = (AGSGraphicsLayer*)[self.mapView mapLayerForName:@"Graphics Layer"];

    [graphicsLayer addGraphic:graphic];

 

The final confusing thing is that when I print the two above NSLog() statements to the console, they both print the same longitude and latitude (with the very minor difference of the delta I'm using to offset them slightly on the map). But the points on the map are literally two continents apart.

 

Am I misunderstanding something about spatial references perhaps???

Howard

0 Kudos
1 Reply
ChristopherMilack1
New Contributor III

You're right - this is a spatial reference issue. The reason your two points are showing up in different locations is because one has the proper spatial reference and the other doesn't. As a general rule of thumb, when you have graphics randomly showing up off the west coast of Africa, this is likely the cause.

If I understand correctly, it's the second point that you show above that does not work correctly. Try changing self.mapView.spatialReference to [AGSSpatialReference wgs84SpatialReference] like you used for the first point. That should do the trick.

0 Kudos