PHP version of micro-letter Js-sdk location to take Street View example

Source: Internet
Author: User

Extensions are based on the Qqmapmodel and Imagecachemodel classes in the micro-credit JS-SDK Geographic interface example. Look at the next Tencent map has a static diagram of the V2 version, I also add to, continue around the Tencent map to take the interface of the street to write. Because it is a demo, like taking Street View there are several parameters can be defined, I only use the default! No more talking about yards.
QQMapModel.class.php: (Note: Api_key with QQ in the official application, currently free)
<?php
namespace Home\model;
Class Qqmapmodel {
Const
Pano_api = ' Http://apis.map.qq.com/ws/streetview/v1/getpano ',
Api_key = ' czqbz-rc53v-2rqpx-ufnbe-fch2j-df00 ';

static public Function call ($url, array $params = null) {
$url = $url. Http_build_query ($params);
$ch = Curl_init ($url);
Curl_setopt_array ($ch, Array (
Curlopt_returntransfer => 1,
Curlopt_followlocation => 1,
Curlopt_autoreferer => 1,
Curlopt_ssl_verifyhost => 0,
Curlopt_ssl_verifypeer => 0,
Curlopt_verbose => 1,
));
$result = curl_exec ($ch);
if (Curl_errno ($ch)) {
return false;
}
Curl_close ($ch);
return $result;
}

New Static Diagram V2 interface
static function Staticmap ($point, $otherParam = Array ()) {
$pos = Explode (', ', $point);
$POSSTR = $pos [1]. $pos [0];
$param = Array (
' Size ' => ' 620*380 ',
' Center ' => $posStr,
' Zoom ' => 13,
' Format ' => ' PNG ',
' Maptype ' => ' Roadmap ',
' Markers ' => $posStr,
' Key ' => Self::api_key,
);
if (count ($otherParam))
$param = Array_merge ($param, $otherParam);
Return ' http://apis.map.qq.com/ws/staticmap/v2/? '. Http_build_query ($param);
}

Take the Street View interface
static function StreetView ($pano, $otherParam = Array ()) {//max 960x640
$param = Array (
' Size ' => ' 620x380 ',
' Pano ' => $pano,
' Heading ' => 0,
' Pitch ' => 0,
' Key ' => Self::api_key,
);
if (count ($otherParam))
$param = Array_merge ($param, $otherParam);
Return ' Http://apis.map.qq.com/ws/streetview/v1/image? '. Http_build_query ($param);
}

ID Interface for Street View
static function Getpano ($location, $otherParam = Array ()) {
$param = Array (
' Location ' => $location,
' Radius ' => 200,
' Output ' => ' json ',
' Key ' => Self::api_key,
);
if (count ($otherParam))
$param = Array_merge ($param, $otherParam);
$result = Self::call (self::P ano_api, $param);
if ($result) {
Return Json_decode ($result, 1);
}
return false;
}

Static Diagram V1 Version interface
static function Mapimage ($point, $otherParam = Array ()) {
$param = Array (
' Size ' => ' 620*380 ',
' Center ' => $point,
' Zoom ' => 13,
' Format ' => ' PNG ',
' Markers ' => $point,
);
if (count ($otherParam))
$param = Array_merge ($param, $otherParam);
Return ' Http://st.map.qq.com/api? '. Http_build_query ($param);
}
}
Imagecachemodel class: (Just add more static methods to the cache of Street View in the previous tutorial)
public static function Getstreetcacheimg ($points) {
$fileName = MD5 ($points);
Self:: $FULL _cache_dir = C (' Public_full_dir '). Self::cache_dir;
$CACHEIMG = self:: $FULL _cache_dir. '/'. $fileName. Self:: $TYPE;
if (file_exists ($CACHEIMG)) {
Return Self::cache_dir. $fileName. Self:: $TYPE;
} else {
$res = Qqmapmodel::getpano ($points);
if ($res [' status '] = = 0) {
$pano = $res [' detail '] [' id '];
$IMAGEURL = Qqmapmodel::streetview ($pano);
Self::savecacheimg ($IMAGEURL, $fileName);
Return Self::cache_dir. $fileName. Self:: $TYPE;
}
Return self::cache_dir ' Default '. Self:: $TYPE;
}
}
Then the processing in controller: (As for the AJAX call in the layout template is similar to the previous geography interface, this is not written here)
Public Function streetpicaction () {
Layout (false);
if (I (' pos ', ') ') {
$target = imagecachemodel::getstreetcacheimg (I (' pos '));
$url = __root__. $target;
Redirect ($url);
}
}

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.