AnsweredAssumed Answered

javascript geocoder returning incorrect coordinates

Question asked by shepa006 on Nov 21, 2014
Latest reply on Nov 25, 2014 by khutchins-esristaff

I was testing the geocoder from the ArcGIS JavaScript API today and noticed some odd behavior. Simply it boils down to if I run the geocoder manually (ie. type the search criteria into the text box and then press enter) then it returns as expected with the result spatial reference and extent matching. However, if I run the geocoder by code (ie. dynamically build the search criteria from other user inputs and pass in the search criteria to the geocoder) then it returns the spatial reference in Web Mercator and the extent coordinates in WGS84. The problem with this is that when I zoom to the result from a find result coming from a code approach the map zooms to the wrong location.

 

Do I need to do something different to the geocoder when passing in search criteria by code?

 

after creating a geocoder I set up a handler for the "find-results"

on(geocoder, "find-results", function (geocodeResults) {

                    console.log(geocoder);

                    console.log("geocode results");

                    console.log(geocodeResults);

                    console.log("geocode results - first extent");

                    geocoder.select(geocodeResults.results.results[0]);

                    console.log("map");

                    console.log(map);

                });

 

for the find by code approach here's how it is handled

 

geocoder.value = 'California, United States';

geocoder.find();

 

 

 

using the same search criteria here are the results from the code and manual approaches:

Results from code

extent: Object

     spatialReference: Object

          latestWkid: 3857

          wkid: 102100

     __proto__: Object

     type: "extent"

     xmax: -114.131258

     xmin: -125.371258

     ymax: 42.87022

     ymin: 31.63022

 

Results from manual

extent: Object

     spatialReference: Object

          latestWkid: 3857

          wkid: 102100

     __proto__: Object

     type: "extent"

     xmax: -12705033.52415573

     xmin: -13956264.600672128

     ymax: 5292238.823753822

     ymin: 3714868.5338891055

 

Outcomes