說兩句:javascript
準備工做:css
拿到key以後,在頁面引入高德API和UI組件庫以及相關CSS文件java
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/> <script src="http://cache.amap.com/lbs/static/es5.min.js"></script> <script src="http://webapi.amap.com/maps?v=1.4.3&key=3853mark的key不告訴你138eacc13d55806d&plugin=AMap.PlaceSearch,AMap.AdvancedInfoWindow"></script> <script src="//webapi.amap.com/ui/1.0/main.js?v=1.0.11"></script>
顯示基礎地圖所用到的HTML和JSweb
<body> <div id="container"></div> </body>
<script type="text/javascript"> var map = new AMap.Map('container', { resizeEnable: true, zoom:11, center: [116.397428, 39.90923]//默認的地圖中心經緯度 }); </script>
引入高德地圖工具包js文件api
<script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
編寫輸入提示須要的HTML標籤瀏覽器
<div> <input id="tipinput" class="form-control input-style" placeholder="請輸入關鍵字" value=""/> </div>
輸入提示和POI搜索插件用到的JS
app
AMap.plugin(['AMap.Autocomplete','AMap.PlaceSearch'],function(){ var autoOptions = { city: "北京", //城市,默認全國 input: "keyword"//使用聯想輸入的input的id(也就是上邊那個惟一的id) }; autocomplete= new AMap.Autocomplete(autoOptions); var placeSearch = new AMap.PlaceSearch({ city:'北京', map:map }) AMap.event.addListener(autocomplete, "select", function(e){ //TODO 針對選中的poi實現本身的功能 placeSearch.setCity(e.poi.adcode); placeSearch.search(e.poi.name) }); });
效果圖工具
小貼士ui