Wht is HTML geo locatiuon and how to use the same

The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
In eduladder you can Ask,Answer,Listen,Earn and Download Questions and Question papers.
Watch related videos of your favorite subject.
Connect with students from different parts of the world.
Apply or Post Jobs, Courses ,Internships and Volunteering opportunity. For FREE
See Our team
Wondering how we keep quality?
Got unsolved questions? Ask Questions

HTML-->View question

Wht is HTML geo locatiuon and how to use the same?

what is HTML Geolocation and how HTML Geolocation API is used to get the geographical position of a user.


Asked On2017-05-17 06:28:51 by:Jhon

Taged users:


Likes:
Be first to like this question

Dislikes:
Be first to dislike this question
Talk about this  Delete  Like  Dislike
View all qusetions

You might like this video:Basics of HTML
Watch more here

Watch more videos from this user Here

Learn how to upload a video and start earning here

Answers

The HTML Geolocation API is used to get the geographical position of a user.

Since this can compromise user privacy, the position is not available unless the user approves it.

Using HTML Geolocation

Use the getCurrentPosition() method to get the user's position.

The example below is a simple Geolocation example returning the latitude and longitude of the user's position:

Example
<script>
var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
}
</script>

Example explained:

  • Check if Geolocation is supported
  • If supported, run the getCurrentPosition() method. If not, display a message to the user
  • If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the parameter ( showPosition )
  • The showPosition() function gets the displays the Latitude and Longitude
The example above is a very basic Geolocation script

Answerd on:2015-01-04 Answerd By:Jeeva

Likes:
Be first to like this answer

Dislikes:
Be first to dislike this answer
Talk about this  Delete  Like  Dislike

You might like this video:Uses of Javascript
Watch more here

Watch more videos from this user Here

Learn how to upload a video and start earning here

The HTML5 geolocation feature lets you find out the geographic coordinates (latitude and longitude numbers) of the current location of your website's visitor. This feature is helpful for providing better browsing experience to the site visitor. For example, you can return the search results that are physically close to the user's location.

<html lang="en"> <head> <meta charset="utf-8"> <title>HTML5 Geolocation</title> <script> function showPosition(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(function(position){ var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")"; document.getElementById("result").innerHTML = positionInfo; }); } else{ alert("Sorry, your browser does not support HTML5 geolocation."); } } </script> </head> <body> <div id="result"> <!--Position information will be inserted here--> </div> <button type="button" onclick="showPosition();">Show Position</button> </body> </html>

Answerd on:2019-06-19 Answerd By:avi738

Likes:
Be first to like this answer

Dislikes:
Be first to dislike this answer
Talk about this  Delete  Like  Dislike

You might like this video:Network and IP Address
Watch more here

Watch more videos from this user Here

Learn how to upload a video and start earning here



Lets together make the web is a better place

We made eduladder by keeping the ideology of building a supermarket of all the educational material available under one roof. We are doing it with the help of individual contributors like you, interns and employees. So the resources you are looking for can be easily available and accessible also with the freedom of remix reuse and reshare our content under the terms of creative commons license with attribution required close.

You can also contribute to our vision of "Helping student to pass any exams" with these.
Answer a question: You can answer the questions not yet answered in eduladder.How to answer a question
Career: Work or do your internship with us.Work with us
Create a video: You can teach anything and everything each video should be less than five minutes should cover the idea less than five min.How to upload a video on eduladder