How to get your Current Location with Javascript | HTML5 Geolocation API
HTML5 Geolocation API
We can get our location using HTML5 Geolocation API. HTML5 Geolocation API is used to return the current position of the users. Any one can get there current location using HTML5 Geolocation API.
Things you should know before using HTML5 Geolocation API
You must have a little knowledge before you starting with HTML5 Geolocation API are:
- HTML
- Javascript
HTML is a markup language which is use for designing web page.
Javascript is a programming language which is use to make web page more interactive.
HTML5 Geolocation API
navigator.geolocation(); //this is use to get geolocation
- First check if your browser is supporting the navigator.geolocation() :
if(navigator.geolocation){
console.log("Your browser is support this function");}
- This will tell you whether your browser is supporting the navigator.geolocation() or not.
Use of getCurrentPosition() :
The getCurrentPosition() function is use to get current position by passing the argument.
The argument will be the function name where we will access the latitude and longitude.
navigator.geolocation().getcurrentLocation(function_name);
Get Latitude and Longitude :
To get the Latitude and Longitude we will now return to the function which was given to the getCurrentLocation() and we will pass an argument in to the function. Let me understand you through example:
navigator.geolocation().getcurrentLocation(getPosition);
//defineing
Comments
Post a Comment