mapqqChajian.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. //腾讯地图的。
  3. class mapqqChajian extends Chajian{
  4. private $mapqq_key = '';
  5. protected function initChajian()
  6. {
  7. $this->getkey();
  8. }
  9. public function getkey()
  10. {
  11. $key = getconfig('qqmapkey');
  12. if(!$key){
  13. $key = $this->rock->jm->base64decode('T0I0QlotRDRXM1UtQjdWVk8tNFBKV1ctNlRLREotV1BCNzc:');
  14. }else{
  15. $this->mapqq_key = $key;
  16. }
  17. //$this->mapqq_key = $key;
  18. return $key;
  19. }
  20. private function mapqqerr($msg=''){
  21. if(!$msg)$msg = '无法访问腾讯地图接口';
  22. return '{"status":201,"message":"'.$msg.'"}';;
  23. }
  24. //获取位置
  25. public function gcoder($lat, $lng)
  26. {
  27. if(!$this->mapqq_key){
  28. $barr = c('xinhuapi')->getdata('mapqq','gcoder', array(
  29. 'lat' => $lat,
  30. 'lng' => $lng,
  31. ));
  32. if(!$barr['success'])return $this->mapqqerr($barr['msg']);
  33. return $barr['data'];
  34. }else{
  35. $url = 'https://apis.map.qq.com/ws/geocoder/v1?key='.$this->mapqq_key.'';
  36. $url.= '&get_poi=0';//不返回周边位置
  37. $url.= '&location='.$lat.','.$lng.'';
  38. $url.= '&poi_options=radius=200';
  39. $result = c('curl')->getcurl($url);
  40. if(!$result)$result = $this->mapqqerr();
  41. return $result;
  42. }
  43. }
  44. //转坐标
  45. public function translate($lat, $lng, $type)
  46. {
  47. if(!$this->mapqq_key){
  48. $barr = c('xinhuapi')->getdata('mapqq','translate', array(
  49. 'lat' => $lat,
  50. 'lng' => $lng,
  51. 'type'=> $type
  52. ));
  53. if(!$barr['success'])return $this->mapqqerr($barr['msg']);
  54. return $barr['data'];
  55. }else{
  56. $url = 'https://apis.map.qq.com/ws/coord/v1/translate?key='.$this->mapqq_key.'';
  57. $url.= '&locations='.$lat.','.$lng.'';
  58. $url.= '&type='.$type.'';
  59. $result = c('curl')->getcurl($url);
  60. if(!$result)$result = $this->mapqqerr();
  61. return $result;
  62. }
  63. }
  64. //搜索$key 是base64
  65. public function suggestion($keyword)
  66. {
  67. if(!$this->mapqq_key){
  68. $barr = c('xinhuapi')->getdata('mapqq','suggestion', array(
  69. 'keyword' => $keyword,
  70. ));
  71. if(!$barr['success'])return $this->mapqqerr($barr['msg']);
  72. return $barr['data'];
  73. }else{
  74. $keyword = $this->rock->jm->base64decode($keyword);
  75. $keyarr = explode(' ', $keyword);
  76. $url = 'https://apis.map.qq.com/ws/place/v1/suggestion?key='.$this->mapqq_key.'';
  77. $url .= '&keyword='.$keyarr[0].'';
  78. if(isset($keyarr[1]))$url.= '&region='.$keyarr[1].'';
  79. $result = c('curl')->getcurl($url);
  80. if(!$result)$result = $this->mapqqerr();
  81. return $result;
  82. }
  83. }
  84. }
粤ICP备19079148号