Geo Location API - Quick JavaScript Interview Questions (2015)

Quick JavaScript Interview Questions (2015)

Chapter 9. Geo Location API

Q. What is Geo Location API?
Geo Location API publishes the location of the user to the web. It needs user’s permission for privacy reason. The Geo location API is present inside navigator.geolocation object.

Q. How to determine Geo Location API is supported in browser? ANSWER
To determine Geo location API is supported in browser can be determined by the truth value of geolocation object inside the navigator object. Below code has the function which returns true or false Boolean value based on the geolocation object present inside the navigator.

function isGeoLocationSupported(){
var flag = navigator.geolocation ? true : false; return flag;

var isSupported = isGeoLocationSupported(); if(isSupported){

console.log("Geo Location API not supprted"); }

The following screenshot shows the output of the above code as the geolocation object is present inside the navigator API.