In a recent project, there is a function of obtaining the surrounding merchants. The geographical positioning system needs to be used.
So I thought of the geographical positioning of H5. After consulting the information, the next code was simply encapsulated.
Const getposition = (timeout = 10000, maximumage = 60000, enablehighacuracy = false) => New Promise (RESOLVE, Reject) => {if (! Navigator &&! Or.Geolocation) {Return Reject (New Error ('Geology API Not supported '))} condials = (loc) => {const local = {latitude: loc.coords.latitude, // latitude longitude: local .coords.accuracy // Precision Degree} Resolve (local)} const error = () => Reject ('') Navigator.Geolocation.getCurrenTposition (Success, ERROR, {ENABLEHIGHACURACY, // Get high -precision position, default // Specify the timeout time for the geographical location. When the default is not limited, the unit is the maximum valid period of milliseconds. .then (pOS => POS) .catch (err => console.log (err))The API of the H5's geographical location is indeed very easy to use, but because the geographical location of the user is the privacy of the user, it is necessary to be authorized by the user.
Regardless of whether the user refuses or allows authorization, the site will be cached by the browser. The next visit will not ask the user again, unless the user removes the regulation manually. The address of the removal of the rules in chrome is set in the settings, as shown in the figure below:
In addition, if the user refuses, you can obtain the latitude and longitude by selecting the IP. Generally, the error will be relatively large.
IPIP.NET is a website that can obtain user geographical information through IP.
The above is all the contents of this article. I hope it will be helpful to everyone's learning. I also hope that everyone will support VEVB Wulin.com.