简体   繁体   中英

How do I pass an address into my javascript API map using URL parameters?

I am using the latest version of the ESRI JavaScript API to build a basemap template. What I would like to do is pass an address parameter into my map so that when it opens the map is zoomed into the address in question. Similar to the examples below:

Viewer for Flex: (link not active) http://myserver.com/flexviewers/actmap/index.html?search=15 Fordham St, Pocatello, Idaho

ArcGIS Online http://www.arcgis.com/home/webmap/viewer.html?find=380 new york st,redlands,ca

How do I do this? Do I need to define parameters within the code or can I simply pass URL parameters to the map like in the above examples to the geocode or locator tools?

The ESRI Javascript API uses DOJO and so you would need to write some JavaScript to take the address in the URL and the pass it to a locator service.

Parsing the URL could be done in DOJO with the following code:

var params = getUrlParams();
var id = params['id']; // or params.id

or use Dojo provides http://dojotoolkit.org/reference-guide/dojo/queryToObject.html

then this link will give you some information on calling the locator service https://developers.arcgis.com/javascript/jssamples/locator_service.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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