简体   繁体   English

如何使用arcGis JavaScript获取地址的纬度

[英]how to get Lat Long of an Address using arcGis JavaScript

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

for the 3.x api would look like this 3.x api看起来像这样

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 https://developers.arcgis.com/javascript/3/jshelp/inside_events.html

For the 2.x api would look like this: 对于2.x api如下所示:

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. 如果您只是想从地图上获取x和y坐标,那么艾登提供的答案就可以了。

If you need to get a location from an Address information. 如果您需要从地址信息中获取位置。 you would need to use GeocodeServer service to get the location. 您将需要使用GeocodeServer服务来获取位置。 You could create and host your own service or use the one of the service hosted by ESRI. 您可以创建和托管自己的服务,也可以使用ESRI托管的服务之一。

http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ 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 https://developers.arcgis.com/javascript/3/jsapi/locator-amd.html#locator1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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