运行以下代码即可
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <title>IP定位获取当前城市</title> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=LjEVnz1queNkEUxV5SMB2Fas"></script> <script type="text/javascript"> var myCity = new BMap.LocalCity(); myCity.get(myFun); function myFun(result){ var cityName = result.name; alert("您所在的城市: "+cityName); } </script> </head> <body> </body> </html>
posted on 2015-07-02 09:51  帅帅的小猪猪  阅读(334)  评论(1编辑  收藏  举报