最近看了一下百度地圖的API,感受十分的好用,而後最近寫了一個調用百度地圖實現獲取城市以及調用本身的數據庫進行計數的一個東西,如今把代碼貼出來:javascript
<?php /** * Created by PhpStorm. * User: onlythen * Date: 5/26/15 * Time: 3:23 PM */ session_start(); require_once("config.php"); $link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD); mysql_select_db($DBNAME); $str="select total from number WHERE id=1"; $result=mysql_query($str); $temp=mysql_fetch_array($result); $number=$temp["total"]; //echo $number; $str2="update number set total=total+1 where id=1"; mysql_query($str2); ?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<!--不可省略-->
<script src="http://api.map.baidu.com/api?v=1.5&ak=CqSmd95LZGbKrsshOnjTNUB3" type="text/javascript"></script>
</head>
<body>
<!--不可省略-->
<div id="bdMapBox" style="display:none;"></div>
<script type="text/javascript"> // 百度地圖API功能 var map = new BMap.Map("bdMapBox"); var nowCity = new BMap.LocalCity(); // var total= document.getElementById("atCity2").innerHTML(); nowCity.get(bdGetPosition); function bdGetPosition(result){ var cityName = result.name; //當前的城市名 /*自定義代碼*/ atCity.innerHTML = cityName; /*自定義代碼*/ window.document.title+="我是在"+cityName+<?php echo $number; ?>+"個"+"祝福高考的"; } </script>
<!--不可省略-->
<p>您當前所在的城市爲:<span id="atCity"></span></p>
<p>您是第多少個訪問的呢?:<span id="atCity2"><?php echo $number; ?></span></p>
</body>
</html>