高德地圖片添加標記
阿新 • • 發佈:2017-08-24
javascrip stat posit scrip pan text function jquer col
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script type="text/javascript" src="jquery.v1.10.2.js"></script> <script type="text/javascript"src="https://webapi.amap.com/maps?v=1.3&key=******"></script> </head> <body> <div id="allmap"></div> <script type="text/javascript"> var marker,map = new AMap.Map("allmap", { resizeEnable: true }); $(function () { $("#allmap").css("height", $(window.parent.document).height() - 123 + "px"); map.plugin(["AMap.CitySearch"], function () { //實例化城市查詢類 var citysearch = new AMap.CitySearch(); //自動獲取用戶IP,返回當前城市citysearch.getLocalCity(function (status, result) { if (status === ‘complete‘ && result.info === ‘OK‘) { if (result && result.city && result.bounds) { var city = result.city; //var citybounds = result.bounds; //alert(city); console.info(city); //myFun(cityinfo); map.setBounds(result.bounds); } } }); }); var position = []; map.on(‘click‘, function (e) { if (marker) { marker.setMap(null); marker = null; } marker = new AMap.Marker({ icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png", position: [e.lnglat.getLng(), e.lnglat.getLat()] }); marker.setMap(map); console.info(position); console.info(e.lnglat.getLng()); console.info(e.lnglat.getLat()); }); }); </script> </body> </html>
高德地圖片添加標記