Is there anyway to track the location (as precise as possible) of a user of a mobile web site?
I am aware that the best way to locate someone is via GPS, but I'm not sure if that is possible through a mobile web site? I also know that you can roughly track a users location via the device's IP address, but I'm not sure if this is the best method?
Looking at Google Maps as an example, the Google Maps website can track my current location pretty much precisely using an iPhone or an Android device. Is this because these sites are activating the device's GPS capabilities, or is there something else going on in order for them to achieve this?
The website I am planning to create will ideally be capable of running on Smartphone devices (such as Android/iPhone/Blackberry/Windows Phone etc), but also be capable of running on non-smartphone devices, which may not have GPS technology built in to query the current location.
Can anyone suggest the best way this could be achieved please? I know that some existing location libraries such as GeoLocation are widely recommended, but again, are these compatible with devices which don't necessarily have GPS technology available?
Thanks in advance.
You can use the HTML5 Geolocation API on devices that support it. It will return the most accurate location that is available which might be A-GPS or wifi location.
See for example this tutorial on how to use geolocation with JavaScript.
Basically you test for geolocation support and request the 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 prompt the user if they want to share their current location or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With