Locating a user of a mobile website

Do I need to track the location (as accurate as possible) of the user of the mobile website?

I know the best way to find someone is via GPS, but I'm not sure if this is possible through a mobile website? I also know that you can roughly track the location of users through the IP address of a device, but I'm not sure if this is the best method?

As an example, for example on Google Maps, the Google Maps website can track my current location to a large extent using an iPhone or Android device. Is it because these sites activate the capabilities of the GPS device, or is there something else to achieve this?

The website that I plan to create will ideally be able to work on Smartphone devices (such as Android / iPhone / Blackberry / Windows Phone, etc.), but it can also work on non-smartphone devices, which may not have GPS built-in technology to query your current location.

Can anyone suggest a better way this can be achieved, please? I know that some existing location libraries, such as GeoLocation, are widely recommended, but again, are they compatible with devices that don't necessarily have GPS technology?

Thanks in advance.

+4
source share
1 answer

You can use the HTML5 geolocation API on devices that support it. It will return the most accurate location that is available, which could be an A-GPS or Wi-Fi location.

See, for example, this tutorial on using geolocation with JavaScript.

Basically you check geolocation support and request a position:

if (navigator.geolocation) { // device can return its location navigator.geolocation.getCurrentPosition(function(position) { console.log(position.coords.latitude); console.log(position.coords.longitude); } } 

Please note that this code will tell the user whether he wants to share his current location or not.

+9
source

Source: https://habr.com/ru/post/1397802/


All Articles