腾讯地图距离计算
function showPosition(position){lat=position.coords.latitude;
lng=position.coords.longitude;
//调用地图命名空间中的转换接口 type的可选值为 1:GPS经纬度,2:搜狗经纬度,3:百度经纬度,4:mapbar经纬度,5:google经纬度,6:搜狗墨卡托
qq.maps.convertor.translate(new qq.maps.LatLng(lat,lng), 1, function(res){
//取出经纬度并且赋值
center = res;
map = new qq.maps.Map(document.getElementById("container"),{
center:center,
zoom: 12
});
//逆地址解析
geocoder = new qq.maps.Geocoder({
complete : function(result){
let district = result.detail.addressComponents.district; //定位到区县
document.getElementById(dwTxt).value(district);
}
});
geocoder.getAddress(center);
//计算两点间的距离
var start = new qq.maps.LatLng(lat, lng);
var endA = new qq.maps.LatLng(38, 115);
var endB = new qq.maps.LatLng(34, 118);
var distanceA = Math.round(qq.maps.geometry.spherical.computeDistanceBetween(start, endA)*10)/10;
var distanceB = Math.round(qq.maps.geometry.spherical.computeDistanceBetween(start, endB)*10)/10;
//判断距离是否大于20000m
if(parseInt(distanceA) <= 20000 && parseInt(distanceB) > 20000){
bababbabababablllalallalala
});
}else if(parseInt(distanceB) <= 20000 && parseInt(distanceA) > 20000){
balbalbalabalbalbalbalbalabalabalabalabalba
});
}else{
aaaaaaaaaaaaaaaaaaa
}
});
}https://lbs.qq.com/webApi/javascriptV2/jsDemo
/**
根据经纬度获取位置信息
get_gps_area_info($longitude,$latitude,$limit);
**/
public function get_gps_area_info($longitude,$latitude,$limit=10,$keyword='',$city_id=0, $rest=0)
{
global $_W;
global $_GPC;
$where = " and state =1 and enable =1 ";
if( $city_id != 0 )
{
$where .= " and city_id = ".$city_id;
}
if( $rest != 0 )
{
$where .= " and rest != 1";
}
if( !empty($keyword) )
{
$where .= " and community_name like '%{$keyword}%' ";
}
// having distance <= 10000距离限制 default_comunity_limit_mile
$limit_mile = $this->get_config_by_name('default_comunity_limit_mile');
$limit_where = '';
if(isset($limit_mile) && !empty($limit_mile) && floatval($limit_mile>0)) $limit_where = 'having distance <= '.floatval($limit_mile)*1000;
$pi = pi();
$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
FROM ".tablename('lionfish_community_head')." where member_id !=0 and uniacid=:uniacid {$where} {$limit_where} order by distance asc limit {$limit}";
$list = pdo_fetchall($sql , array(':uniacid' => $_W['uniacid']));
$result = array();
if( !empty($list) )
{
foreach($list as$val)
{
$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']));
if(empty($mb_info)) continue;
$tmp_arr = array();
$tmp_arr['communityId'] = $val['id'];
$tmp_arr['communityName'] = $val['community_name'];
$province = $this->get_area_info($val['province_id']);
$city = $this->get_area_info($val['city_id']);
$area = $this->get_area_info($val['area_id']);
$country = $this->get_area_info($val['country_id']);
//address
$full_name = $province['name'].$city['name'].$area['name'].$country['name'].$val['address'];
$tmp_arr['fullAddress'] = $full_name;
$tmp_arr['communityAddress'] = '';
$tmp_arr['disUserName'] = $val['head_name'];
//ims_
$tmp_arr['headImg'] = $mb_info['avatar'];
$tmp_arr['disUserHeadImg'] = '';
$tmp_arr['rest'] = $val['rest'];
$tmp_arr['lat'] = $val['lat'];
$tmp_arr['lon'] = $val['lon'];
$distance = $val['distance'];
if($distance >1000)
{
$distance = round($distance/1000,2).'公里';
}else{
$distance = $distance.'米';
}
$tmp_arr['distance'] = $distance;
$result[] = $tmp_arr;
}
}
return $result;
}
页:
[1]