Free Essay SamplesAbout UsContact Us Order Now

Geolocation and Web Storage

0 / 5. 0

Words: 275

Pages: 1

57

Geolocation in a Webpage
Firstname LastnameUniversity Name
Geolocation in a Webpage
In HTML5, the geographical location of a user can be accessed through the geolocation API and JavaScript. As the user manually allows access to his/her geographical location, the feature does not compromise privacy (see Figure 1). Geolocation is supported in almost all the widely used browsers i.e. Firefox, Opera, Chrome, Internet Explorer and Safari.

Figure SEQ Figure * ARABIC 1 API seeking user’s permission
To access a person’s location (i.e. the latitude and longitude), the Geolocation API is used as shown in Figure 2. A JavaScript function getLocation() uses the API to get user location.

Figure SEQ Figure * ARABIC 2 Geolocation in WebPage – HTML Code

Figure SEQ Figure * ARABIC 3 User Location
Check Browser Support
First it is checked through the global navigator object, navigator.geolocation, whether the Geolocation API is supported by the browser. If the API is not supported, a message can be displayed to indicate that to the user.
Get User’s Location
If the user’s browser supports Geolocation API, the navigator.geolocation object’s getCurrentPosition() function will execute and return the coordinates object. The function can be passed three parameters: showPosition (i.e. the callback function that would access the position details), showError (i.e. the callback function to reveal any errors) and optn (i.e. for setting options for position). Mostly only the showPosition parameter is used (as used in Figure 2).

Wait! Geolocation and Web Storage paper is just an example!

The showPosition() function is triggered only if the user has allowed discovery of his/her location and if the browser has successfully fetched the position object. This position object is passed as input to the function. The position object contains the ‘coords’ object. The user’s latitude and longitude are accessed using the latitude and longitude properties of ‘coords’ object, as shown below.
The showError() and optn are optional parameters. The showError() function is used to indicate the cause of error e.g. time out, unknown error, user denied access or location unavailable. The optn parameter is used to set options for location information retrieval such as accuracy, age and timeout.

References
Srinisavan, K. (2013). HTML5 Geolocation. Retrieved from https://www.sitepoint.com/html5-geolocation/

Get quality help now

Top Writer

Arnold Foster

5.0 (218 reviews)

Recent reviews about this Writer

Thanks for the awesome essay! I’ve got an A-grade, and my teacher said it was the best paper in the class! I would definitely use your services again if I need help with my homework.

View profile

Related Essays

Sunjata the Archetypal Hero

Pages: 1

(275 words)

Case Study Drug Addiction

Pages: 1

(275 words)

Favorite Movie

Pages: 1

(275 words)

Recism and Health

Pages: 1

(275 words)

Brain Plasticity.#2(R.M)

Pages: 1

(275 words)

Security Assessment

Pages: 1

(275 words)

Business Communication Skill

Pages: 1

(275 words)

Legal Marijuana

Pages: 1

(550 words)

Drug Abuse Challenge

Pages: 1

(275 words)