PHP Baidu Map coordinates drawing rectangle call Baidu Poi Search Rectangle area Data

Source: Internet
Author: User
Tags auth

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,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.