查看: 950|回复: 0

腾讯地图距离计算

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2024-5-26 13:05:13 | 显示全部楼层 |阅读模式
  1. function showPosition(position){
  2.             lat=position.coords.latitude;
  3.             lng=position.coords.longitude;
  4.             //调用地图命名空间中的转换接口   type的可选值为 1:GPS经纬度,2:搜狗经纬度,3:百度经纬度,4:mapbar经纬度,5:google经纬度,6:搜狗墨卡托
  5.             qq.maps.convertor.translate(new qq.maps.LatLng(lat,lng), 1, function(res){
  6.                   //取出经纬度并且赋值
  7.                   center = res[0];
  8.                   map = new qq.maps.Map(document.getElementById("container"),{
  9.                         center:  center,
  10.                         zoom: 12
  11.                     });
  12.                   //逆地址解析
  13.                   geocoder = new qq.maps.Geocoder({
  14.                         complete : function(result){
  15.                           let district = result.detail.addressComponents.district;   //定位到区县
  16.                           document.getElementById(dwTxt).value(district);
  17.                         }
  18.                   });
  19.                   geocoder.getAddress(center);

  20.                   //计算两点间的距离
  21.                   var start = new qq.maps.LatLng(lat, lng);
  22.                   var endA = new qq.maps.LatLng(38, 115);
  23.                   var endB = new qq.maps.LatLng(34, 118);
  24.                   var distanceA = Math.round(qq.maps.geometry.spherical.computeDistanceBetween(start, endA)*10)/10;
  25.                   var distanceB = Math.round(qq.maps.geometry.spherical.computeDistanceBetween(start, endB)*10)/10;
  26.                   //判断距离是否大于20000m
  27.                   if(parseInt(distanceA) <= 20000 && parseInt(distanceB) > 20000){
  28.                    bababbabababablllalallalala
  29.                     });
  30.                   }else if(parseInt(distanceB) <= 20000 && parseInt(distanceA) > 20000){
  31.                     balbalbalabalbalbalbalbalabalabalabalabalba
  32.                     });
  33.                   }else{
  34.                     aaaaaaaaaaaaaaaaaaa
  35.                   }
  36.              });
  37.           }
复制代码
https://lbs.qq.com/webApi/javascriptV2/jsDemo
  1. /**
  2.                 根据经纬度获取位置信息
  3.                 get_gps_area_info($longitude,$latitude,$limit);
  4.         **/
  5.         public function get_gps_area_info($longitude,$latitude,$limit=10,$keyword='',$city_id=0, $rest=0)
  6.         {
  7.                 global $_W;
  8.                 global $_GPC;
  9.                
  10.                 $where = " and state =1 and enable =1 ";
  11.                 if( $city_id != 0 )
  12.                 {
  13.                         $where .= " and city_id = ".$city_id;
  14.                 }
  15.                 if( $rest != 0 )
  16.                 {
  17.                         $where .= " and rest != 1";
  18.                 }
  19.                 if( !empty($keyword) )
  20.                 {
  21.                         $where .= " and community_name like '%{$keyword}%' ";      
  22.                 }
  23.                
  24.                 // having distance <= 10000距离限制 default_comunity_limit_mile
  25.                 $limit_mile = $this->get_config_by_name('default_comunity_limit_mile');
  26.                 $limit_where = '';
  27.                 if(isset($limit_mile) && !empty($limit_mile) && floatval($limit_mile>0)) $limit_where = 'having distance <= '.floatval($limit_mile)*1000;

  28.                
  29.                 $pi = pi();
  30.                
  31.                 $sql = "select *, ROUND(6378.138*2*ASIN(SQRT(POW(SIN(({$latitude}*{$pi}/180-lat*{$pi}/180)/2),2)+COS({$latitude}*{$pi}/180)*COS(lat*{$pi}/180)*POW(SIN(({$longitude}*{$pi}/180-lon*{$pi}/180)/2),2)))*1000) AS distance
  32.                  FROM ".tablename('lionfish_community_head')." where member_id !=0 and uniacid=:uniacid {$where} {$limit_where} order by distance asc limit {$limit}";
  33.                
  34.                 $list = pdo_fetchall($sql , array(':uniacid' => $_W['uniacid']));
  35.                
  36.                 $result = array();
  37.                
  38.                 if( !empty($list) )
  39.                 {
  40.                         foreach($list as  $val)
  41.                         {
  42.                                 $mb_info = pdo_fetch("select avatar,username from ".tablename('lionfish_comshop_member')." where uniacid =:uniacid and member_id=:member_id ", array(':uniacid' => $_W['uniacid'], ':member_id' => $val['member_id']));
  43.                                 if(empty($mb_info)) continue;
  44.                               
  45.                                 $tmp_arr = array();
  46.                                 $tmp_arr['communityId'] = $val['id'];
  47.                                 $tmp_arr['communityName'] = $val['community_name'];
  48.                                 $province = $this->get_area_info($val['province_id']);
  49.                                 $city = $this->get_area_info($val['city_id']);
  50.                                 $area = $this->get_area_info($val['area_id']);
  51.                                 $country = $this->get_area_info($val['country_id']);
  52.                                 //address
  53.                                 $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$val['address'];
  54.                               
  55.                                 $tmp_arr['fullAddress'] = $full_name;
  56.                                 $tmp_arr['communityAddress'] = '';
  57.                                 $tmp_arr['disUserName'] = $val['head_name'];
  58.                                 //ims_
  59.                                  
  60.                                 $tmp_arr['headImg'] = $mb_info['avatar'];
  61.                                 $tmp_arr['disUserHeadImg'] = '';
  62.                                 $tmp_arr['rest'] = $val['rest'];
  63.                                 $tmp_arr['lat'] = $val['lat'];
  64.                                 $tmp_arr['lon'] = $val['lon'];
  65.                                 $distance = $val['distance'];
  66.                               
  67.                                 if($distance >1000)
  68.                                 {
  69.                                         $distance = round($distance/1000,2).'公里';
  70.                                 }else{
  71.                                         $distance = $distance.'米';
  72.                                 }
  73.                                 $tmp_arr['distance'] = $distance;
  74.                               
  75.                                 $result[] = $tmp_arr;
  76.                         }
  77.                 }
  78.                 return $result;
  79.                
  80.         }
复制代码


道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部