Small micro-channel program acquiring position

Obtaining position getLocation

wx.getLocation({
 type: 'wgs84',
 success (res) {
   const latitude = res.latitude
   const longitude = res.longitude
   const speed = res.speed
   const accuracy = res.accuracy
 }
})

wgs84 return gps coordinates, gcj02 coordinates may be used to return the wx.openLocation

Open the map

wx.getLocation({
 type: 'gcj02', //返回可以用于wx.openLocation的经纬度
 success (res) {
   const latitude = res.latitude
   const longitude = res.longitude
   wx.openLocation({
     latitude,
     longitude,
     scale: 18
   })
 }
})

wgs84 is a global positioning system, to obtain the coordinates, gcj02 are the coordinates given by the State Bureau of Surveying and Mapping.
gcj02 Mars coordinate system, the National Bureau measured coordinate system released in 2002, it is an encryption algorithm for latitude and longitude data, that is adding random deviations. High German, Tencent, Google China Maps. The most widely used coordinate system.
High moral map, Tencent Maps and Google in China map using GCJ-02 coordinate system.
Baidu map using a BD-09 coordinate system.
Level Interface (HTML5 Geolocation or ios, Andrews API) used by the device acquires GPS coordinates are WGS-84 coordinate system.

Longitude 0 ° --180 ° (eastbound denoted E) 0 ° --180 ° (westbound denoted W) Latitude 0 ° --90 ° N, 0 ° --90 ° S.
Run Park North Gate
Tencent map coordinates, 118.284618,33.920469. (LNG, LAT)
high moral map coordinates, 118.284614,33.920445. (LNG, LAT)
Baidu map coordinates, 118.291152,33.926284. (LNG, LAT)

Online conversion, http://www.gpsspg.com/maps.htm

Conversion of latitude and longitude, turn Tencent Baidu High German.

/**
 * 中国正常GCJ02坐标---->百度地图BD09坐标
 * 腾讯地图用的也是GCJ02坐标
 * @param double $lng 经度
 * @param double $lat 纬度
 * @return array
 */
public static function Convert_GCJ02_To_BD09($lng, $lat)
{
    $x_pi  = 3.14159265358979324 * 3000.0 / 180.0;
    $x     = $lng;
    $y     = $lat;
    $z     = sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
    $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);
    $lng   = $z * cos($theta) + 0.0065;
    $lat   = $z * sin($theta) + 0.006;
    return array('lng' => $lng, 'lat' => $lat);
}


/**
 * 百度地图BD09坐标---->中国正常GCJ02坐标
 * 腾讯地图用的也是GCJ02坐标
 * @param double $lng 经度
 * @param double $lat 纬度
 * @return array
 */
public static function Convert_BD09_To_GCJ02($lng, $lat)
{
    $x_pi  = 3.14159265358979324 * 3000.0 / 180.0;
    $x     = $lng - 0.0065;
    $y     = $lat - 0.006;
    $z     = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
    $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
    $lng   = $z * cos($theta);
    $lat   = $z * sin($theta);
    return array('lng' => $lng, 'lat' => $lat);
}

gcj02

'lng' => '118.34593200683594'
'lat' => '33.9527587890625'

wgs84

'lng' => '118.34032440185547'
'lat' => '33.95400619506836'

Experiments show that if you want to compare Tencent map coordinates distance, please use gcj02 get coordinates.

Guess you like

Origin www.cnblogs.com/jiqing9006/p/11404023.html