reverse geocoding is always time out

3343
6
Jump to solution
01-23-2014 10:33 PM
ChiranjeeviGK
New Contributor III
Hi

i am using Locator for geocoding as below

           this.locator = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");             //on(this.locator,"location-to-address-complete", lang.hitch(this,"_reverseGeocodingSuccess"));             //on(this.locator,"address-to-locations-complete", lang.hitch(this,"_geocodingSuccess"));


and i have added a click event listener as below

getAddress : function(/*Point*/ point)         {              this.locator.locationToAddress(webMercatorUtils.webMercatorToGeographic(point),100,              function(address){                 alert(address);             },function(err){                 alert(err);             });         },


Problem

always it says time out,


But from this example code its working fine
Locator sample
0 Kudos
1 Solution

Accepted Solutions
ChiranjeeviGK
New Contributor III
in my code the event when the click is happen we have to pass the Point object to locator, with proper spatial reference

so in the code
           
on(map,"click",function(mapEvent){                 locator.locationToAddress(new Point(mapEvent.x,mapEvent.y),100);             });


we have to pass mapEvent.mapPoint which is having proper spatial reference

on(map,"click",function(mapEvent){                 locator.locationToAddress(mapEvent.mapPoint,100);             });


Will work..

View solution in original post

0 Kudos
6 Replies
RobertoPepato
Occasional Contributor II
Hi

i am using Locator for geocoding as below

           this.locator = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
            //on(this.locator,"location-to-address-complete", lang.hitch(this,"_reverseGeocodingSuccess"));
            //on(this.locator,"address-to-locations-complete", lang.hitch(this,"_geocodingSuccess"));


and i have added a click event listener as below

getAddress : function(/*Point*/ point)
        {

            this.locator.locationToAddress(webMercatorUtils.webMercatorToGeographic(point),100,
             function(address){
                alert(address);
            },function(err){
                alert(err);
            });
        },


Problem

always it says time out,


But from this example code its working fine
Locator sample


Could your post or provide a link for your full code?
0 Kudos
ChiranjeeviGK
New Contributor III
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>ArcGIS API Locator</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
    <style>
        html, body,#map {
            height: 100%; width: 100%; margin: 0; padding: 0;
        }
    </style>
    <script src="http://js.arcgis.com/3.8compact/"></script>
    <script>
        var map;
        require([ "esri/tasks/locator","esri/map", "dojo/on","esri/geometry/Point","dojo/domReady!"],
        function(Locator,Map,on,Point){
            map = new Map("map", {
                basemap : "streets",
                center: [-89.985, 29.822],
                zoom: 8
            });

            var locator = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
            on(locator,"location-to-address-complete", function(evet)
            {
                alert(evet);
            });
            on(locator,"address-to-locations-complete",function(evet)
            {
                alert(evet);
            });

            on(map,"click",function(mapEvent){
                locator.locationToAddress(new Point(mapEvent.x,mapEvent.y),100);
            });

        });
    </script>
</head>

<body>
            <div id="map">

                </div> <!-- end drop shadow divs -->
</body>
</html>



Error i can see is:

XHR finished loading: "http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/reverseG�?�%2C%22spatialReference%22%3A%7B%22wkid%22%3A4326%7D%7D&distance=100&f=json"

Error {code: 400, message: "Cannot perform query. Invalid query parameters.", details: Array[1], log: undefined, httpCode: 400�?�}
0 Kudos
RobertoPepato
Occasional Contributor II
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>ArcGIS API Locator</title>

    <link rel="stylesheet" href="http://js.arcgis.com/3.8/js/esri/css/esri.css">
    <style>
        html, body,#map {
            height: 100%; width: 100%; margin: 0; padding: 0;
        }
    </style>
    <script src="http://js.arcgis.com/3.8compact/"></script>
    <script>
        var map;
        require([ "esri/tasks/locator","esri/map", "dojo/on","esri/geometry/Point","dojo/domReady!"],
        function(Locator,Map,on,Point){
            map = new Map("map", {
                basemap : "streets",
                center: [-89.985, 29.822],
                zoom: 8
            });

            var locator = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
            on(locator,"location-to-address-complete", function(evet)
            {
                alert(evet);
            });
            on(locator,"address-to-locations-complete",function(evet)
            {
                alert(evet);
            });

            on(map,"click",function(mapEvent){
                locator.locationToAddress(new Point(mapEvent.x,mapEvent.y),100);
            });

        });
    </script>
</head>

<body>
            <div id="map">

                </div> <!-- end drop shadow divs -->
</body>
</html>



Error i can see is:


Oh I see. You're trying to use the x and y properties provided for your parameter. These are coordinates related to the screen position, not the map coordinates. Instead, use the mapPoint property that is already provided to you through your event params, like this:

on(map,"click",function(mapEvent){
    locator.locationToAddress(mapEvent.mapPoint,100);
});


If you're curious about the diferences in these units, take a look in the ScreenPoint documentation:

https://developers.arcgis.com/javascript/jsapi/screenpoint-amd.html

You can inspect the different values on your javascript console:

console.log(mapEvent.x);
console.log(mapEvent.y);
console.log(mapEvent.mapPoint.x);
console.log(mapEvent.mapPoint.y);


Let me know if this worked for you.

Regards.

Roberto Pepato
0 Kudos
ChiranjeeviGK
New Contributor III
i have already tried that..

it give error saying invalid query parameters

Error
_ssl: undefined
code: 400
details: Array[1]
httpCode: 400
log: undefined
message: "Cannot perform query. Invalid query parameters."
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: d
0 Kudos
RobertoPepato
Occasional Contributor II
i have already tried that..

it give error saying invalid query parameters

Error
_ssl: undefined
code: 400
details: Array[1]
httpCode: 400
log: undefined
message: "Cannot perform query. Invalid query parameters."
stack: (...)
get stack: function () { [native code] }
set stack: function () { [native code] }
__proto__: d



This is probably happening because you're clicking on an point that don't have any street or geocode information on the specified range. You will always see this happening, for example, if you click on the ocean.

You'll find a message error explaining what's happening if you inspect the details array of your error object. Try to zoom in at the street level and click over one street. See if the error persists.

Take a look here too see it working.
0 Kudos
ChiranjeeviGK
New Contributor III
in my code the event when the click is happen we have to pass the Point object to locator, with proper spatial reference

so in the code
           
on(map,"click",function(mapEvent){                 locator.locationToAddress(new Point(mapEvent.x,mapEvent.y),100);             });


we have to pass mapEvent.mapPoint which is having proper spatial reference

on(map,"click",function(mapEvent){                 locator.locationToAddress(mapEvent.mapPoint,100);             });


Will work..
0 Kudos