Problem Description: Retrieves the latitude and longitude information of a place name in a map based on a place name
Preparation: Corresponding map service support, including map data support, ArcGIS API pack
Code Show:
Need to introduce ArcGIS Apirequire (["Esri.task.FindTask", "Esri.task.FindParameters", "Esri.task.QueryTask", "Esri.task.Quer Y "],function (findtask,findparameters,querytask,query) {///first through Findtask, which supports multiple layers of query var f = new Findtask (" HTTP/ Server.arcgisonline.com/arcgis/rest/services/ngs_topo_us_2d/mapserver ");//arcgis map Service, here is just an example of var params = new Findparameters ();p arams.layerids = [0,1,2,3]; The sequence number of the layer params.searchfields = ["NAME"];//the field to query, can be multiple params.searchtext = "Beijing"; To query the content, this is a fuzzy match, will be on this map service so "Beijing" in the beginning of the place to find out params.returngeometry = true; Whether to return the geometry attribute value, note that this minor latitude and longitude is f.execute from this attribute (params,showresults); Showresults is the return function, the value returned by the query is in this callback function Showresults (results) {Console.dir (results);//This is the result set of the query, print it out to see clearly the F or (Var i=0;i<results.length;i++) {var graphic = results[i]; A point of information var xy = Graphic.feature.geometry;var x = xy.x; Longitude var y = xy.y; Latitude}}//the second kind of querytask this can only retrieve one layer of var qt = new Querytask ("Http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Top O_us_2d/mapServer/1 "); var q = new Query (); q.returngeometry = True;q.outfields = [' * ']; Return field, can be multiple, * denotes all Q.where = "NAME like '% Beijing% '"//Can be standard Sqlqt.execute (q,res); Res is the back function res (RESUTLS) {//results is the return result set for (Var i=0;i<results.features.length;i++) {var graphic = Res Ults.features[i];console.dir (graphic); var xy = Graphic.geometry;var x = xy.x; Longitude var y = xy.y; Latitude}});
If you have questions, you can check the official api:https://developers.arcgis.com/javascript/jsapi/of ArcGIS
Also can message exchange study, I was just contact with ArcGIS
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Retrieving the latitude and longitude of the place name according to the place name