Things You Will Need:
- Google Chrome Browser or Firefox, You can use any latest browser but this script will not work on old browsers.
- Server for running the script. You can use Apache or any other server.
We are going to use
The following lines of code will tell you whether this browser supports Geo-location or not.
alert('Your Browser does not support HTML5 Geo Location. Please Use Newer Version Browsers');
Here is the code which shows the Latitude and Longitude of the user.
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var accuracy = position.coords.accuracy;
document.getElementById("lat").value = latitude;
document.getElementById("lng").value = longitude;
document.getElementById("acc").value = accuracy;
alert('ERROR(' + err.code + '): ' + err.message);
When you execute this code, the browser will ask to allow the location access. You need to click on the Allow button to run the code or to find where am i right now.
If you are going to create a script by which a user can share his/her current location by a location link then you have to use a GET method in PHP. If you need any help HTML Geo-location script you can ask in comments.