GPS经纬度转换为百度坐标


android客户端:

Import

import com.baidu.mapapi.CoordinateConvert;
import com.baidu.mapapi.GeoPoint;

Code

GeoPoint p = new GeoPoint(x, y);
GeoPoint p2 = CoordinateConvert.bundleDecode(CoordinateConvert.fromWgs84ToBaidu(p));

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM