JS API - Convert Easting/Northing to Latitude/Longitude

1102
3
07-11-2019 02:13 AM
ScottWilson2
New Contributor II

How do i convert Easting and Northing to Latitude and Longitude using the JavaScript API?

I have a rest service which returns an array of objects, each object contains geometry x and y coordinates, i believe this is Easting and Northing

var items = [{
{
 "attributes": {
   "OBJECTID": 18342
},
 "geometry": {
   "x": 250067.50299999956,
   "y": 659477.8800000008
 }‍‍‍‍‍‍‍‍
}]‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I'm using the Point class to try and pin each coordinate to my map, but i believe this class requires latitude and longitude format: https://developers.arcgis.com/javascript/3/jsapi/point-amd.html

Using 3.28

thanks

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Scott,

   The APIs Point class does not require the Latitude and Longitude. You can provide X and Y in any coordinates system as long as you specify the SpatialReference for the Point. I.E. new Point(x, y, spatialReference). So you need to know your data spatial reference. If you are adding this data to a map that is using different SpatilalReference then you will have to Project your data to WKID 102100 WebMercator. https://developers.arcgis.com/javascript/3/jsapi/geometryservice-amd.html#project

ScottWilson2
New Contributor II

Hi Robert, thanks for your help.

I have spoken to our GIS professional and they advised that we are using British National Grid (27700).  I have added this SpatialReference to my map and the points are now displaying, albeit of the coast of Nigeria! 

var point = new Point(items[key].geometry.x, items[key].geometry.y, new SpatialReference({ wkid: 27700 }) );

I guess i need to project my data to WebMercator but even after looking at the documentation link you provide, i'm still not exactly sure how i code this

thanks

Scott

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Scott,

   It is not to hard.

var point = new Point(items[key].geometry.x, items[key].geometry.y, new SpatialReference({ wkid: 27700 }) );
var gsvc = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
var params = new ProjectParameters();
params.geometries = [point];
params.outSR = map.spatialReference;
gsvc.project(params, function(results){
    // do something with the results here
  });
);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos