1. 程式人生 > >12 week work

12 week work

呼叫一個地圖API

 1 <html>
 2 <head>
 3     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 4     <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
 5     <style type="text/css">
 6         body, html,#allmap {width: 100%;height: 100%;overflow
: hidden;margin:0;font-family:"宋體";} 7 </style> 8 <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=dNX82XCV8CiBGd8np6ArPLc4tFLvR7SI"></script> 9 <title>IP定位獲取當前城市</title> 10 </head> 11 <body> 12 <div id="allmap"></
div> 13 </body> 14 </html> 15 <script type="text/javascript"> 16 var map = new BMap.Map("allmap"); 17 var point = new BMap.Point(116.331398,39.897445); 18 map.centerAndZoom(point,12); 19 20 function myFun(result){ 21 var cityName = result.name; 22 map.setCenter(cityName);
23 alert("當前定位城市:"+cityName); 24 } 25 var myCity = new BMap.LocalCity(); 26 myCity.get(myFun); 27 </script>