SIMXXX Locate My Position on Gaode Map

From Waveshare Wiki
Jump to: navigation, search

Overview

SIM7600X 4G HAT is popular due to its complete features and stable performance, but some netizens have complained that while SIM7600X 4G HAT is good for internet access, there is a significant difference between the location data obtained by SIM7600X and my actual location (when the coordinates obtained by SIM7600X are checked on Baidu or AutoNavi(Gaode) map), with several streets' difference. Let's take a walk into the streets of GNSS and see who is using space-time transfer:

Hardware Preparation

Hardware Connection

SIMXXX-GNSS.png

Software Preparation

Principle Analysis

The coordinate system used by SIM7600X is the WGS-84 coordinate system, while SIM820X uses the Mars coordinate system (gcj_02); and the commonly used Baidu or AutoNavi maps use the encrypted Baidu coordinate (bd09) and the Mars coordinate system (gcj_02). Therefore, directly placing the WGS-84 coordinate system on Baidu or AutoNavi(Gaode) maps will result in significant errors (it can be placed on Google Maps); in addition, the latitude and longitude obtained by SIMXXX are measured in minutes, and need to be converted to the commonly used degree units first: 1200px-SIM7600-GNSS-flow chat.png

SIMXXX Obtain Latitude and Longitude Location Information

Due to unstable GPS signal acquisition indoors, please place the module or antenna on the balcony or next to the window, or conduct the experiment directly outdoors. Plug in the GPS antenna and place the receiver label face down in an open outdoor area. Under normal conditions (outdoor, good weather, no large buildings blocking), it will take about 1 minute to receive the positioning signal after powering on; if the weather conditions are poor, the positioning time may be longer, or even unable to be positioned

  • Send the following command to turn on GPS:
AT+CGPSAUTO=1 
AT+CVAUXS=1
  • Use the following command to get latitude, longitude, and other location information:
AT+CGPSINFO
  • Open NEMA for detailed information
sudo minicom -D /dev/ttyUSB1
  • Unit conversion
ddmm.mm--> dd.mm.ss: The degree remains the same, the minute *100/60; for example, 2232.448620--> 22.(32448620*100/60)= 22.54081033
  • Key code for coordinate system conversion
def wgs84_to_gcj02(lng, lat):
    """
    WGS84 to GCJ02 (Mars coordinate system)
    :param lng: Longitude of WGS84 coordinate system
    :param lat: Latitude of WGS84 coordinate system
    :return:
    """
    dlat = _transformlat(lng - 105.0, lat - 35.0)
    dlng = _transformlng(lng - 105.0, lat - 35.0)
    radlat = lat / 180.0 * pi
    magic = math.sin(radlat)
    magic = 1 - ee * magic * magic
    sqrtmagic = math.sqrt(magic)
    dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi)
    dlng = (dlng * 180.0) / (a / sqrtmagic * math.cos(radlat) * pi)
    mglat = lat + dlat
    mglng = lng + dlng
    return [mglng, mglat]
def wgs84_to_bd09(lon, lat):
    lon, lat = wgs84_to_gcj02(lon, lat)
    return gcj02_to_bd09(lon, lat)
 
def _transformlng(lng, lat):
    ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + \
          0.1 * lng * lat + 0.1 * math.sqrt(math.fabs(lng))
    ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 *
            math.sin(2.0 * lng * pi)) * 2.0 / 3.0
    ret += (20.0 * math.sin(lng * pi) + 40.0 *
            math.sin(lng / 3.0 * pi)) * 2.0 / 3.0
    ret += (150.0 * math.sin(lng / 12.0 * pi) + 300.0 *
            math.sin(lng / 30.0 * pi)) * 2.0 / 3.0
    return ret
 
def _transformlat(lng, lat):
    ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + \
          0.1 * lng * lat + 0.2 * math.sqrt(math.fabs(lng))
    ret += (20.0 * math.sin(6.0 * lng * pi) + 20.0 *
            math.sin(2.0 * lng * pi)) * 2.0 / 3.0
    ret += (20.0 * math.sin(lat * pi) + 40.0 *
            math.sin(lat / 3.0 * pi)) * 2.0 / 3.0
    ret += (160.0 * math.sin(lat / 12.0 * pi) + 320 *
            math.sin(lat * pi / 30.0)) * 2.0 / 3.0
    return ret

Run the demo and copy the generated coordinates to the AutoNavi Map API

sudo rm /usr/lib/python3.11/EXTERNALLY-MANAGED
sudo pip3 install --upgrade pip
sudo pip3 install pynmea2
sudo pip3 install pynmeagps
wget https://files.waveshare.com/wiki/common/SIMXXX-GNSS.zip
sudo unzip SIMXXX-GNSS.zip
sudo python3 SIMXXX-GNSS.py

SIMXXX longitude,latitude.png

114.0832857092161,22.53842762954979

My Location

Positioning by the window on the south side of the World Trade Center, and there is an error of no more than 10 meters between the positioning and the location of the editor; Different test environments and conversion algorithms may have different errors.
SIMXXX gaode.png

More Related Tutorial