且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP+百度地图API+JAVASCRIPT实现GPS坐标与百度坐标转换的实例

更新时间:2022-08-18 22:29:54

原文: PHP+百度地图API+JAVASCRIPT实现GPS坐标与百度坐标转换的实例

<!--小幅的坐标转换点位程序-->
<!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>