mohamed
mohamed

Reputation: 253

How to convert an ios esri arcGIS Point into latitude and longitude

I have a service return arcgis json format , i want to convert this geometry points to longitude and latitude ios example :

"geometryType": "esriGeometryPoint",
   "geometry": {
    "x": 445340.99496,
    "y": 2423705.6300004,
    "spatialReference": {
     "wkid": 32637,
     "latestWkid": 32637
    }
   }

i convert the point

AGSGraphic *testGraphic = [[AGSGraphic alloc] initWithJSON:jsonData] ;

how i can get from AGSGraphic longitude and latitude

Upvotes: 2

Views: 1048

Answers (2)

Abd Aboudi
Abd Aboudi

Reputation: 341

I think that you want to change the spatial reference based on what you want .

Ex :

    //AA : Get the clicked point
    let gpsPoint = clickedMapPoint
    let engine = AGSGeometryEngine.defaultGeometryEngine()

    //AA : Change the spatial ref to get real lon and lat
    let mapPoint = engine.projectGeometry(gpsPoint, toSpatialReference: AGSSpatialReference.wgs84SpatialReference()) as! AGSPoint

Upvotes: 1

mohamed
mohamed

Reputation: 253

this solved the problem , just send xPoint and yPoint and it will return CLLocation Object contain lng and latit

 -(CLLocation *) convertToLongAndLat:(double) xPoint andYPoint :(double) yPoint {

        double originShift = 2 * M_PI * 6378137 / 2.0;

        double lon = (xPoint / originShift) * 180.0;
        double lat = (yPoint / originShift) * 180.0;

        lat = 180 / M_PI * (2 * atan( exp( lat * M_PI / 180.0)) - M_PI / 2.0);

        return [[CLLocation alloc] initWithLatitude:lat longitude:lon];
    }

Upvotes: 2

Related Questions