描述:此示例演示如何使用Geocoder的小工具,以简化的过程中,发现在地图上的位置。地理搜索框添加到应用程序
在线演示:http://help.arcgis.com/en/webapi/javascript/arcgis/samples/locator_simple/index.html
参考Geocoder API:http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/#geocoder
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /> <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/> <title>ArcGIS API for JavaScript | Simple Geocoding</title> <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css"> <style> html, body, #map { height:100%; width:100%; margin:0; padding:0; } #search { display: block; position: absolute; z-index: 2; top: 20px; left: 74px; } </style> <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3"></script> <script> // 导入包 dojo.require("esri.map"); dojo.require("esri.dijit.Geocoder"); var map, geocoder; dojo.ready(function() { // 创建地图 map = new esri.Map("map",{ basemap: "gray", // 指定的地图底图。以下是有效的选项:"streets","satellite","hybrid","topo","gray","oceans","national-geographic","osm". center: [-120.435, 46.159], // 地图居中的经纬度 zoom: 7 // 缩放级别 }); // 创建 geocoder geocoder = new esri.dijit.Geocoder({ map: map // 必填项:地图 }, "search"); geocoder.startup(); // 启动 }); </script> </head> <body> <div id="search"></div> <div id="map"></div> </body> </html>
效果如下:
未经允许请勿转载:程序喵 » ArcGIS For JavaScropt Geocoder —— 搜索地名