GPS经纬度转换为百度坐标
android客户端:
|
Import import com.baidu.mapapi.CoordinateConvert; Code GeoPoint p = new GeoPoint(x, y); 其变量p为从GPS直接读到的点,p2为在在地图上显示的点; |
PHP 网页:
<?php function getgps($lats,$lngs, $gps=false, $google=false) { $lat=$lats; $lng=$lngs; if($gps) $c=file_get_contents("http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=$lng&y=$lat"); else if($google) $c=file_get_contents("http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=$lng&y=$lat"); else return array($lat,$lng); $arr=(array)json_decode($c); if(!$arr[\'error\']) { $lat=base64_decode($arr[\'y\']); $lng=base64_decode($arr[\'x\']); } return array($lat,$lng); } ?>