Geolocation | Basics
In general Geolocation is an Application Program Interface (API) of HTML5 that allows us to get 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 main stream 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:
- getCurrentPosition()
This method returns the user location.
- watchPosition()
This method returns in the interval position of the device.
- clearWatch()
This method is for canceling an operation.
Geolocation | Attributes
The following is the most used and important attributesa for Geolocation purposes:
- coords: This attribute gathers the information about the location.
- Heading and speed.
- cords.latitude: This attributes measures latitude in decimal systems.
- cords.longitude: This measures geographical longitude.
- Unit: decimal systems
- cords.altitude: this attribute measures the altitude in meters.
- cords.accuracy: Accuracy of the altitude.
- Height
- Unit: meters
- cords.altitudeAccuracy: This attribute defines the accuracy of the altitude.
- Unit: meters
- cords.heading: direction of movement of the device in degrees in a clockwise manner or the direction to the north.
- cords.speed: This attributes defines the actual speed of the device.
- Speed is measured in mt/sec
- 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
abhishekPolohu function()
{
Var = navigator.geolocation Geolocation,
Geolocation.getCurrentPosition (savePosition, checkError);
}
checkError function(error)
{
if(chyba.code==0)
{
// unknown error
}
else if(chyba.code==1)
{
// access is denied
}
else if(chyba.code==2)
{
// position of the device is unknown
}
else if(chyba .code==3)
{
// time interval has passed
}
}
function(position)
{
var width = pozicia.coords.latitude;
var height = pozicia.coords.longitude;
}