| |
The above code is commonly seen in H5-related geolocation implementations. It uses the device’s own GPS for positioning, but through testing I found it was very inaccurate. The desktop version would directly throw errors.
- On mobile, if you use Baidu’s API set, the location drifts significantly. Based on observation, it uses cell tower positioning.
- I then thought β is Baidu really this bad? So I tried the native code above, and found it frequently errors out:
Error using Geolocation method: error.POSITION_UNAVAILABLE
After investigating for a long time, the desktop version just wouldn’t work. Finally I figured it out β key point:
GPS services now strongly prefer HTTPS. HTTP is increasingly unsupported. Chrome even explicitly states that geolocation requires HTTPS.
After testing again with HTTPS, the accuracy was incredible β within 10 meters.