您如何使用arcgis Javascript获取纬度和经度?
答案 0 :(得分:1)
对于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
对于2.x api,看起来像这样:
dojo.connect(map, "onClick", mapClick);
function mapClick(evt){
console.log(evt.mapPoint)
}
答案 1 :(得分:1)
如果您只想获得x& y坐标来自地图,答案由艾登提供。
如果您需要从地址信息中获取位置。您需要使用GeocodeServer服务来获取位置。您可以创建和托管自己的服务,也可以使用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){
....
});
});
有关定位器任务的详细信息,请访问以下位置。
https://developers.arcgis.com/javascript/3/jsapi/locator-amd.html#locator1