first, put out three important methods
/**
*@date: 2017-07-12 9:23 *@auth: Web Search *@parame: Baidu map PHP version of the call method * *functionCACULATEAKSN ($ak, $sk, $url, $querystring _arrays, $method = ' get ') {if($method = = = ' POST ')
{Ksort ($querystring _arrays); } $querystring = Http_build_query ($querystring _arrays); returnMD5 UrlEncode ($url. '? ')
$querystring. $sk)); }
/**
*@date: 2017-07-12 10:57 *@auth: Baidu Map Document * Baidu coordinate system into a standard GPS seating system *@paramfloat $lnglat Coordinates (for example: 106.426, 29.553404) *@returnThe standard GPS value after string conversion: * *functionBD09LLTOWGS84 ($lnglat) {//longitude, latitude $lnglat = explode (', ', $lnglat);List($x, $y) = $lnglat;
$Baidu _server = "http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x={$x}&y={$y}";
$result = @file_get_contents ($Baidu _server); $json = Json_decode ($result);if($json->error = 0)
{$bx = Base64_decode ($json->x);
$by = Base64_decode ($json->y);
$GPS _x = 2 * $x-$BX; $GPS _y = 2 * $y-$by; return$GPS _x ', '. $GPS _y;//longitude, latitude}Else return$lnglat; }
/**
*@date: 2017-07-12 11:34 *@auth: Leishaofa *@parameDraw a rectangle based on a GPS coordinate@parame$LNG Longitude *@parame$lat Latitude *@parame$distance 1-kilometer * *functionResultmap ($LNG, $lat, $distance =1) {$fEARTH _radius=6371;//earth mean radius $dlng =2*asin (sin ($distance/(2* $fEARTH _radius))/co
S (Deg2rad ($lat)));
$DLNG =rad2deg ($DLNG);
$dlat = $distance/$fEARTH _radius; $dlat =rad2deg ($dlat);Return Array(' Left-top ' =>Array(' lat ' => $lat + $dlng, ' LNG ' => $lng-$dlng), ' Right-top ' =>Array(' lat ' => $lat + $dlng, ' LNG ' => $lng + $dlng), ' Left-bottom ' =>Array(' Lat ' => $lat-$dlng, ' LNG ' => $lng-$dlng), ' Right-bottom ' =>Array(' Lat ' => $lat-$dlng, ' LNG ' => $LNG + $dlng)); }
look at the controller method
$gps =explode (', ', $this->bd09lltowgs84 (' 114.282167,30.553489 '));
$dao = $this->resultmap ($gps [0], $gps [1]);
$url = "http://api.map.baidu.com/place/v2/search?query= convenience store, &bounds=". $dao [' Left-bottom '] [' lat ']. ",
". $ dao[' Left-bottom ' [' LNG ']. ",". $dao [' right-top '] [' lat ']. ",". $dao [' right-top '] [' LNG '].
"&output=json&page_size=10&page_num=1&ak=" C (' Baiduak ');
$ch = Curl_init (); curl_setopt ($ch,