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); } ?>