AnsweredAssumed Answered

AGSPoint Issue - PointWithX Not Accepting Coordinates

Question asked by darrenes on Apr 7, 2014
Latest reply on May 6, 2014 by darrenes
I'm sure this is something simple I'm missing, but I'm just not seeing it. I'm trying to add a single point abject to a graphics layer and no matter what I do, the point is always showing up just off the western coast of Africa (basically, center of the world map). This is under 10.2 and Xcode 5.1.

My code to do this is as follows:

- (void) plotPoints {     //--- Add a sample point. ---//     //--- First, set up a symbol for the point. ---//     AGSSimpleMarkerSymbol *myMarkerSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol];          myMarkerSymbol.color = [UIColor blueColor];          //--- Now, create a point for the graphic to be drawn. ---//     AGSPoint *myPoint = [AGSPoint pointWithX:-96.6477 y:33.0477 spatialReference:self.mapView.spatialReference];          //--- Create a graphic using the marker and point. ---//     AGSGraphic *myGraphic = [AGSGraphic graphicWithGeometry:myPoint symbol:myMarkerSymbol attributes:nil];          //--- Add the graphic to the graphic layer. ---//     [self.graphicsLayer addGraphic:myGraphic];    } 


This is being called from my viewDidLoad after opening a base map (ArcGIS Online) and adding the graphic layer. The point displays fine with the exception of the location never changing. Is there somehow a difference in the spatialReference that is causing the coordinates to be thrown out?

Edit: After further playing around, it does appear that this is an issue with the coordinate system between the map and the coordinates I'm providing. How do I go about converting from X/Y to whatever units the map is using?

Edit 2: I found a prior post that had the following algorithm in it that has my point in the proper area now.

    //convert longitude and latitude to map point X Y     double mercatorX = longitude * 0.017453292519943295 * 6378137.0;     double a = latitude * 0.017453292519943295;     double mercatorY = 3189068.5 * log((1.0 + sin(a))/(1.0 - sin(a)));


This will get me where I need to be, but it seems like there should be a built in method to do this. I'd prefer to use something a bit more standard if possible.

Outcomes