Use LatLon instead of xy

07-23-2019 02:24 AM
Occasional Contributor


Following code is working well by giving xy to input but I want to give input of longitude and latitude instead of xy in Arcgis REST API. Is there any possible way to resolve my problem.

Egge-Jan PolléRobert Scheitlin, GISPKelly HutchinsRene Rubalcava

  view.ui.add('latlon', 'top-right')
                let lat = document.getElementById('lat');
                let lon = document.getElementById('lon');
                let btn = document.getElementById('latlonBtn');
                btn.addEventListener('click', addfeature )

                function addfeature() {
                    const url = "https://localhost:6443/arcgis/rest/services/KarachiSDE/FeatureServer/0";

                        url: url,
                        features: [{
                            "geometry": { "x": lat.value, "y": lon.value },
                            "attributes": {
                                "Name": document.getElementById('name').value,
                                "ID": document.getElementById('OID').value,
                                "City": document.getElementById('city').value
                    }).then(response => {
                    lat.value = " ";
                    lon.value = " ";
                    document.getElementById('name').value = " ";
                    document.getElementById('OID').value = " ";
                    document.getElementById('city').value = " "

0 Kudos
4 Replies
MVP Regular Contributor

Hi kawish abbas,

The value and the format of the coordinates you have to provide depends on the Spatial Reference of the service you are talking to.

So, in the Lahore Tiger example I have given in this thread I did use coordinates with WKID 102100 (which is essentially EPSG: 3857) to land on the lawn of Lahore Fort, because that is the WKID used by this service: 

So the question is: what is the Spatial Reference of your Karachi service? If you provide coordinates in the same Spatial Reference your point will appear correctly on the map.

Does this answer your question?


      "attributes" : {
        "HazardType" : "Dangerous Animal",
        "Description" : "We saw a tiger on the lawn",
        "SpecialInstructions" : "No Action",
        "Status" : "Active",
        "Priority" : "High"
      "geometry" : {
        "x" : 8272644.51,
        "y" : 3709258.71
0 Kudos
Occasional Contributor

Thank you Egge-Jan Pollé‌ for your kind response.

Spatial reference of service is 4326. when i put coordinates in meter(309,387.886, 2,806,452.684) it works correctly but when i give coordinates in decimal degree(67.105684  , 25.362634) it does not work properly.

0 Kudos
MVP Regular Contributor

Hmmmm, that sounds strange to me. (And it is contrary to what I state above...)

In the help (Add Features—ArcGIS REST API: Services Directory | ArcGIS for Developers) Esri uses an example with decimal degrees.

Could you please check the output of your service?

According to the help:

The structure of each feature in the array is the same as the structure of the json feature object returned by the ArcGIS REST API.

What do you get in the output? Decimal degrees or meters?


0 Kudos
Occasional Contributor

Hi Egge-Jan Pollé

Unit of service is esriMeter and getting geometry coordinates also in meter.

0 Kudos