js GPS 百度地图坐标转换

首先要引用百度地图的 <scrtipt>:

<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>


然后将 GPS 坐标转换为百度地图的坐标:

//GPS坐标
var xx = 119.51026579044;
var yy = 32.395685050929;
//alert(xx+','+yy);
var gpsPoint = new BMap.Point(xx,yy);

//坐标转换,地理坐标转换成平面坐标

BMap.Convertor.translate(gpsPoint,0,translateCallback);

//坐标转换完之后的回调函数
function translateCallback(point){
   //alert(point.lng + "," + point.lat);
   Ds.set('Latitude',point.lng);
   Ds.set('Longitude',point.lat);
   // 百度地图API功能
   var point = new BMap.Point(point.lng,point.lat);
   var gc = new BMap.Geocoder();
   gc.getLocation(point, function(rs){
       var addComp = rs.addressComponents;
       //alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
       $scope.dinner.address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber;
   });
}


你可能感兴趣的:(js GPS 百度地图坐标转换)