<!--大幅的行車路線地圖,帶座標轉換-->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?php
$jingwei="new BMap.Point($longitude,$latitude);"
?>
<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>
<h2 align="center">環評項目定位</h2>
<div style="width:800px;height:500px;margin-left: auto;margin-right: auto;border:1px solid gray"id="container"></div>
<?php include("foot.php");?>
</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); //設置中心點
var pointb=new BMap.Point(116.138100,39.729679);//設置起始點房山環保局
var driving = new BMap.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});//駕車路線
driving.search(pointb, point);//兩點駕車
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>
PS:這主要是我爲單位編寫的從單位出發至污染源的路徑規劃。