ArcGIS中的地理编码功能在线



我需要从地名(即美利坚合众国、弗吉尼亚州、夏洛茨维尔(获得范围(边界框(。在JS API中要调用的适当函数是什么?

我想以编程的方式来做这件事,就好像我在搜索小部件中键入了它一样。

该地图是用JS API制作的:

<script src="https://js.arcgis.com/4.12"></script>
map=new Map({ basemap:baseMap, });                          
activeView=app.mapView=new MapView({                                                                                         
container:container, map:map                                                                 
});

我可以使用这样的REST函数,但必须有一个内部函数:

url="http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?f=pjson&SingleLine="+loc;
$.ajax( { url: url, dataType: 'jsonp' } ).done(function(res) {                      
extent=res.candidates[0].extent;                                          
}); 

使用jquery AJAX还不错,通过使用esri/tasks/locator类及其addressToLocations方法,您可以实现与ESRI API相同的功能

require(["esri/tasks/locator"], function(Locator) {
var locator = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
locator.addressToLocations(loc).then(function(res) {
console.log(res);
var extent = res.candidates[0].extent;    
});

最新更新