Geolocation in HTML5

Geolocation | Basics

 
 
In general, Geolocation is an Application Program Interface (API) of HTML5 that allows us to get the current position or location. To provide this important functionality HTML5 uses functions and some concepts of JavaScript.
 

Use of JavaScript

 
JavaScript is used to get these basic details to search your base location. Through JavaScript, we will get
 
  • Latitude
  • Height
  • Longitude
  • Altitude
  • Heading
  • Speed
  • Timestamp
  • Area
  • Region boundary
  • Accuracy
These details will be obtained to enable the mainstream code to access or get location information. 
 

Geolocation | Scope

 
Nowadays, nearly all browsers and mobile devices support this API. To work with location information or those basic details, what we really need is only a supporting device or frame.
 

Geolocation | Concept

 
We will use the Geolocation API directly. The major idea or concept behind Geolocation is the creation of an instance of an object. (Generally, all programmers are familiar with this concept of creating an object instance.)
 
 
Object Creation
 
For example: var = navigator.geolocation Geolocation,
 
Geolocation |Methods
 
The following are the 3 main methods for creating Geolocation:
  1. getCurrentPosition()
    This method returns the user location.   
  2. watchPosition()
    This method returns in the interval position of the device. 
  3. clearWatch()
    This method is for canceling an operation.

Geolocation | Attributes

 
The following is the most used and important attributes for Geolocation purposes:
  1. coords: This attribute gathers the information about the location.
                  - Heading and speed.
  2. cords.latitude: This attributes measure latitude in decimal systems.
  3. cords.longitude: This measures geographical longitude.
                                   - Unit: decimal systems 
  4. cords.altitude: this attribute measures the altitude in meters.
  5. cords.accuracy: Accuracy of the altitude.
                               - Height
                                 - Unit: meters
  6. cords.altitudeAccuracy: This attribute defines the accuracy of the altitude.
                                             - Unit: meters
  7. cords.heading: the direction of movement of the device in degrees in a clockwise manner or the direction to the north.
  8. cords.speed: This attribute defines the actual speed of the device.
                            - Speed is measured in mt/sec
  9. timestamp: the time when the location information was obtained as well as the instance of the object created, defined by the attribute TIMESTAMP.

Geolocation | Reference Example

  1. abhishekPolohu  function () {  
  2.     Var = navigator.geolocation Geolocation, Geolocation.getCurrentPosition(savePosition, checkError);  
  3. }  
  4. checkError  function (error) {  
  5.     if (chyba.code == 0) {} else if (chyba.code == 1) {} else if (chyba.code == 2) {} else if (chyba.code == 3) {}  
  6. }  
  7.   
  8. function (position) {  
  9.     var width = pozicia.coords.latitude;  
  10.     var height = pozicia.coords.longitude;