<!--小幅的座標轉換點位程序-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
$jingwei="new BMap.Point($longitude,$latitude);";
//$jingwei="new BMap.Point(116.12511,39.72228);";// 測試用的
?>
<title>環評項目定位</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="http://dev.baidu.com/wiki/static/map/API/examples/script/convertor.js"></script> <!--引用用座標轉換腳本-->
</head>
<body>
<div style="width:700px;height:250px;margin-left: auto;margin-right: auto;border:1px solid gray"id="container"></div>
</body>
</html>
<script type="text/javascript">
translateCallback = function (point){ //轉換座標
map.clearOverlays();
var marker = new BMap.Marker(point); //創立座標點
map.addOverlay(marker); //加入標註
map.setCenter(point);//將傳來的點值設爲中心點
marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳動的動畫
map.centerAndZoom(point,15); //設置中心點
map.addControl(new BMap.NavigationControl()); // 添加平移縮放控件
map.addControl(new BMap.ScaleControl()); // 添加比例尺控件
map.addControl(new BMap.MapTypeControl()); //添加地圖類型控件
map.setCurrentCity("房山"); // 設置地圖顯示的城市 此項是必須設置的
map.enableScrollWheelZoom(true);//鼠標縮放
}
var map = new BMap.Map("container",{mapType: BMAP_NORMAL_MAP}); //設置普通地圖爲底圖
var gpsPoint = <?php echo $jingwei?>//將PHP的經緯度值傳給JS
BMap.Convertor.translate(gpsPoint,0,translateCallback);//調用座標轉換函數
</script>
PHP+百度地圖API+JAVASCRIPT實現GPS座標與百度座標轉換的實例
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.