+91 88606 33966            edu_sales@siriam.in                   Job Opening : On-site Functional Trainer/Instructor | Supply Chain Management (SCM)
HTML5 GEO-LOCATION API

API (Application Programming Interfaces) Application Programming Interfaces Stand in HTML5. It is a set of routines, protocols, and tools for building software applications.

An API is a collection of pre-built components, that can be used with JavaScript

It is a set of programming codes that enables data transmission between one software application, website, and another.

It also contains the terms of this data exchange between server and HTML.

Geo-location in HTML5 is used to share the location with some websites and be aware of the exact location. It is mainly used for local businesses, and restaurants, or showing locations on the map. It uses JavaScript to give latitude and longitude to the backend server. Most browsers support Geolocation API.

The Geolocation has following methods which make it interesting and easier to work.

  • getCurrentPosition(): It fetches the current location of the user.
  • watchPosition():It fetches periodic updates of the user’s current location.
  • clearWatch(): It cancels a watchPosition call currently in execution.

Example1 : This example explains returning the user’s location using the getcurrentPosition() method.


HTML Geolocation

Click the button to get your coordinates.

The onclick attribute specifies that the getlocation() function should be called when the button is clicked and the two paragraph elements with the ids “paraID” and “paraID1.” They will be used to display the latitude and longitude.

The getlocation() function is triggered when the button is clicked. It uses navigator.geolocation.watchPosition to continuously monitor the user’s position and calls the showLoc function whenever the position changes.

The showLoc function takes a pos parameter, representing the position. It updates the HTML content of variable1 with the latitude and variable2 with the longitude obtained from the pos object.

HTML5 GEO-LOCATION API

Leave a Reply

Your email address will not be published. Required fields are marked *


Scroll to top