轉:http://www.360doc.com/content/16/0320/14/18636294_543805051.shtml
結果圖:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的密鑰"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
<title>GPS轉百度</title>
</head>
<body>
<div id="allmap"></div>
<script type="text/javascript">
// 百度地圖API功能
//GPS坐標
var xx = 116.397428;
var yy = 39.90923;
var gpsPoint = new BMap.Point(xx,yy);
//地圖初始化
var bm = new BMap.Map("allmap");
bm.centerAndZoom(gpsPoint, 15);
bm.addControl(new BMap.NavigationControl());
//添加谷歌marker和label
var markergps = new BMap.Marker(gpsPoint);
bm.addOverlay(markergps); //添加GPS標注
var labelgps = new BMap.Label("我是GPS標注哦",{offset:new BMap.Size(20,-10)});
markergps.setLabel(labelgps); //添加GPS標注
//坐標轉換完之后的回調函數
translateCallback = function (point){
var marker = new BMap.Marker(point);
bm.addOverlay(marker);
var label = new BMap.Label("我是百度標注哦",{offset:new BMap.Size(20,-10)});
marker.setLabel(label); //添加百度label
bm.setCenter(point);
alert(point.lng + "," + point.lat);
}
setTimeout(function(){
BMap.Convertor.translate(gpsPoint,0,translateCallback); //真實經緯度轉成百度坐標
}, 2000);
</script>
</body>
</html>
歡迎加入,Java,前端的共同學習【愛問共享編程部落】 479668591
