更多最新文章请浏览http://b.unprofessional.pw

本文将用PHP实现 GPS坐标转换成百度地图坐标

百度的地图转换接口只能一次转换一对坐标 一旦坐标多的话十分麻烦

本文将实现批量转换的功能

百度坐标体系:http://developer.baidu.com/map/question.htm#qa004

$url = "http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=".$lng."&y=".$lat."&callback=BMap.Convertor.cbk_".rand(1000,9999)."";
$str=fle_get_contents($url);
//from参数 0表示标准GPS坐标 2表示Google坐标
$startPosition = strlen('BMap.Convertor.cbk_3744&&BMap.Convertor.cbk_3744(');
$strLength = strlen($str)-$startPosition-1;
$str = substr($str,$startPosition,$strLength);
$tempObject = json_decode($str);
//$tempObject是一个json的对象
//error 错误代码 0表示无错误
//x 纬度 base64加密 $latitude = base64_decode($tempObject->x);
//y 经度 base64加密 $longitude= base64_decode($tempObject->y);