AnsweredAssumed Answered

Using geometryEngine projectGeometry results in strange results

Question asked by on May 12, 2013
Latest reply on May 26, 2013 by

I looked in the other threads and cannot find anything about this problem. Maybe it's my misunderstanding of the way to project a point.

I need to convert device's latitude and longitude to my map which is in a 3163 spatial reference.

I do the following :

  • Get the current location from SDK's CoreLocation framework

  • When I need to plot a point on current location, I initialize the current lat/long as an AGSPoint with a WGS84 spatial reference.

  • Then I project it to the spatial reference 3163 and I add this point to one of my graphic layer

This results in the point being misplaced all the time. I first tried the following :
   _defaultSpatialRef = [AGSSpatialReference spatialReferenceWithWKID:3163];      AGSGeometryEngine *engine = [AGSGeometryEngine defaultGeometryEngine];     AGSPoint *point = [AGSPoint pointWithX:currentLocation.coordinate.latitude y:currentLocation.coordinate.longitude spatialReference:[AGSSpatialReference spatialReferenceWithWKID:WKID_WGS84]];     AGSPoint *projectedPoint= (AGSPoint*)[engine projectGeometry:point toSpatialReference:_defaultSpatialRef];

This sample code always result in returning "nan" information in the resulting AGSpoint x and y coordinates. Because I was not sure how to map X and Y as latitude and longitude I tried to switch lat / long so that X is mapped to longitude and Y mapped to latitude in my origin WGS84 point.

This time, I get results but the resulting point seems to be outside my map's bounds.

Here are my information :

  • location latitude = -22.2682

  • location longitude = 166.442

First try when mapping X with latitude and Y with longitude in my initial point that I project => nan / nan as resulting projected AGSPoint X and Y

Second try when mapping X with longitude and Y with latitude :

  • projected point X = 445586.569662

  • projected point Y = 214879.873427

I think my X should be negative but not sure.
Here are my questions :
- Which way should I map X/Y to lat/long (in all other examples I saw X->lat and Y->lng but it does not give any result)
- Am I doing it the right way or missing anything ?

Thank you very much for your time and answers.