Retrieving the latitude and longitude of the place name according to the place name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.