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"));getAddress : function(/*Point*/ point) { this.locator.locationToAddress(webMercatorUtils.webMercatorToGeographic(point),100, function(address){ alert(address); },function(err){ alert(err); }); },Solved! Go to Solution.
on(map,"click",function(mapEvent){ locator.locationToAddress(new Point(mapEvent.x,mapEvent.y),100); });on(map,"click",function(mapEvent){ locator.locationToAddress(mapEvent.mapPoint,100); });Hi
i am using Locator for geocoding as belowthis.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 belowgetAddress : 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
<!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>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�?�}
<!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:
on(map,"click",function(mapEvent){
locator.locationToAddress(mapEvent.mapPoint,100);
});
console.log(mapEvent.x); console.log(mapEvent.y); console.log(mapEvent.mapPoint.x); console.log(mapEvent.mapPoint.y);
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
on(map,"click",function(mapEvent){ locator.locationToAddress(new Point(mapEvent.x,mapEvent.y),100); });on(map,"click",function(mapEvent){ locator.locationToAddress(mapEvent.mapPoint,100); });