小程序新增坐标转换

This commit is contained in:
devil 2020-09-14 22:45:31 +08:00
parent 9dac5101f4
commit 3a8c7f2cf7
8 changed files with 65 additions and 110 deletions

View File

@ -336,24 +336,6 @@ class ConfigService
}
}
// 坐标处理
if(!empty($data) && is_array($data) && in_array(APPLICATION_CLIENT_TYPE, config('shopxo.coordinate_transformation')))
{
foreach($data as &$v)
{
// 坐标转换 百度转火星(高德,谷歌,腾讯坐标)
if(isset($v['lng']) && isset($v['lat']))
{
$map = \base\GeoTransUtil::BdToGcj($v['lng'], $v['lat']);
if(isset($map['lng']) && isset($map['lat']))
{
$v['lng'] = $map['lng'];
$v['lat'] = $map['lat'];
}
}
}
}
// 自提点地址列表数据钩子
$hook_name = 'plugins_service_site_extraction_address_list';
Hook::listen($hook_name, [

View File

@ -1317,21 +1317,6 @@ class OrderService
{
// 销售模式+自提模式 地址信息
$data = Db::name('OrderAddress')->where(['order_id'=>$order_id])->find();
// 坐标处理
if(!empty($data) && is_array($data) && in_array(APPLICATION_CLIENT_TYPE, config('shopxo.coordinate_transformation')))
{
// 坐标转换 百度转火星(高德,谷歌,腾讯坐标)
if(isset($data['lng']) && isset($data['lat']))
{
$map = \base\GeoTransUtil::BdToGcj($data['lng'], $data['lat']);
if(isset($map['lng']) && isset($map['lat']))
{
$data['lng'] = $map['lng'];
$data['lat'] = $map['lat'];
}
}
}
return empty($data) ? [] : $data;
}

View File

@ -418,21 +418,6 @@ class UserService
$is_default = false;
foreach($data as &$v)
{
// 坐标处理
if(in_array(APPLICATION_CLIENT_TYPE, config('shopxo.coordinate_transformation')))
{
// 坐标转换 百度转火星(高德,谷歌,腾讯坐标)
if(isset($v['lng']) && isset($v['lat']))
{
$map = \base\GeoTransUtil::BdToGcj($v['lng'], $v['lat']);
if(isset($map['lng']) && isset($map['lat']))
{
$v['lng'] = $map['lng'];
$v['lat'] = $map['lat'];
}
}
}
// 地区
$v['province_name'] = RegionService::RegionName($v['province']);
$v['city_name'] = RegionService::RegionName($v['city']);

View File

@ -68,7 +68,7 @@ App({
// 请求地址
request_url: "{{request_url}}",
request_url: 'http://shopxo.com/',
// request_url: 'https://dev.shopxo.net/',
request_url: 'https://dev.shopxo.net/',
// 基础信息
application_title: "{{application_title}}",
@ -531,14 +531,7 @@ App({
this.showToast('事件值格式有误');
return false;
}
var map = this.BMapTransqqMap(parseFloat(values[2]), parseFloat(values[3]));
wx.openLocation({
name: values[0],
address: values[1],
longitude: map.lng,
latitude: map.lat
});
this.open_location(values[2], values[3], values[0], values[1]);
break;
// 拨打电话
@ -802,18 +795,48 @@ App({
}, 100);
},
BMapTransqqMap(lng, lat) {
  let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  let x = lng - 0.0065;
  let y = lat - 0.006;
  let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
  let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
  let lngs = z * Math.cos(theta);
  let lats = z * Math.sin(theta);
  return {
    lng: lngs,
    lat: lats
  };
},
/**
* 百度坐标BD-09到火星坐标GCJ02(高德谷歌腾讯坐标)
* object 回调操作对象
* method 回调操作对象的函数
*/
map_bd_to_gcj(lng, lat) {
  let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  let x = lng - 0.0065;
  let y = lat - 0.006;
  let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
  let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
  let lngs = z * Math.cos(theta);
  let lats = z * Math.sin(theta);
  return {
    lng: lngs,
    lat: lats
  };
},
/**
* 百度坐标BD-09到火星坐标GCJ02(高德谷歌腾讯坐标)
* lng 经度
* lat 纬度
* name 地图上面显示的名称
* address 地图上面显示的详细地址
* scale 缩放比例范围5~18
*/
open_location(lng, lat, name, address, scale) {
if(lng == undefined || lat == undefined || lng == '' || lat == '') {
this.showToast('坐标有误');
return false;
}
// 转换坐标打开位置
var position = this.map_bd_to_gcj(parseFloat(lng), parseFloat(lat));
wx.openLocation({
name: name || '',
address: address || '',
scale: scale || 18,
longitude: position.lng,
latitude: position.lat
});
},
});

View File

@ -365,14 +365,9 @@ Page({
return false;
}
var lng = parseFloat(data.lng || 0);
var lat = parseFloat(data.lat || 0);
wx.openLocation({
latitude: lat,
longitude: lng,
scale: 18,
name: data.name || data.alias || '',
address: (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || ''),
});
// 打开地图
var name = data.name || data.alias || '';
var address = (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || '');
app.open_location(data.lng, data.lat, name, address);
},
});

View File

@ -107,22 +107,17 @@ Page({
// 地图查看
address_map_event(e) {
var index = e.currentTarget.dataset.index || 0;
var ads = this.data.data_list[index] || null;
if (ads == null)
var data = this.data.data_list[index] || null;
if (data == null)
{
app.showToast("地址有误");
return false;
}
var lng = parseFloat(ads.lng || 0);
var lat = parseFloat(ads.lat || 0);
wx.openLocation({
latitude: lat,
longitude: lng,
scale: 18,
name: ads.alias || '',
address: (ads.province_name || '') + (ads.city_name || '') + (ads.county_name || '') + (ads.address || ''),
});
// 打开地图
var name = data.alias || '';
var address = (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || '');
app.open_location(data.lng, data.lat, name, address);
},
// 地址内容事件

View File

@ -91,17 +91,12 @@ Page({
if ((this.data.extraction || null) == null) {
return false;
}
var data = this.data.extraction;
var ads = this.data.extraction;
var lng = parseFloat(ads.lng || 0);
var lat = parseFloat(ads.lat || 0);
wx.openLocation({
latitude: lat,
longitude: lng,
scale: 18,
name: ads.alias || '',
address: (ads.province_name || '') + (ads.city_name || '') + (ads.county_name || '') + (ads.address || ''),
});
// 打开地图
var name = data.alias || '';
var address = (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || '');
app.open_location(data.lng, data.lat, name, address);
},
// 进入取货订单管理

View File

@ -124,17 +124,12 @@ Page({
app.showToast("地址有误");
return false;
}
var data = this.data.detail.address_data;
var ads = this.data.detail.address_data;
var lng = parseFloat(ads.lng || 0);
var lat = parseFloat(ads.lat || 0);
wx.openLocation({
latitude: lat,
longitude: lng,
scale: 18,
name: ads.alias || '',
address: (ads.province_name || '') + (ads.city_name || '') + (ads.county_name || '') + (ads.address || ''),
});
// 打开地图
var name = data.alias || '';
var address = (data.province_name || '') + (data.city_name || '') + (data.county_name || '') + (data.address || '');
app.open_location(data.lng, data.lat, name, address);
},
// 下拉刷新