简体   繁体   中英

how to get Lat Long of an Address using arcGis JavaScript

嗨,如何使用arcgis Javascript获取纬度和经度?

for the 3.x api would look like this

require(["esri/map"], function(Map) {
  var map = new Map("mapDiv"),
  map.on("click", myClickHandler);

  function myClickHandler(evt) {
    console.log(evt)
  }
});

https://developers.arcgis.com/javascript/3/jshelp/inside_events.html

For the 2.x api would look like this:

dojo.connect(map, "onClick", mapClick);
function mapClick(evt){
     console.log(evt.mapPoint)
}

If you just want to get the x & y coordinates from Map, the Answer provided by Aiden works.

If you need to get a location from an Address information. you would need to use GeocodeServer service to get the location. You could create and host your own service or use the one of the service hosted by ESRI.

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/

require(["esri/tasks/locator", ... 
], function(Locator, ... ) {
    var locator = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer");
    var address = {"Single Line Input": "100 main street"};
    var params = {address: address, searchExtent: map.extent};              
    locator.outSpatialReference= map.spatialReference;
    locator.addressToLocations(params).then(function(addressCandidates){
        ....
    });
});

Details about the Locator task can be found at below location.

https://developers.arcgis.com/javascript/3/jsapi/locator-amd.html#locator1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM