mapqqChajian.php 2.4 KB

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