HTML Questions & Answers – Geolocation API

This set of HTML Multiple Choice Questions & Answers (MCQs) focuses on “Geolocation API”.

1. Which method is used to get user’s position?
a) getCurrentPosition()
b) getDirectPosition()
c) post()
d) getDirection
View Answer

Answer: a
Explanation: For getting user’s position we used getCurrentPosition() method. Syntax is navigator.geolocation.getCurrentPosition(showPosition). It is supported by most of the browsers like Chrome, Firefox, Internet Explorer, Opera etc.

2. What does showPosition() returns?
a) only latitude
b) only longitude
c) both latitude and longitude
d) direction
View Answer

Answer: c
Explanation: showPosition() method returns both latitude and longitude of user. Syntax is navigator.geolocation.getCurrentPosition(showPosition); The value of latitude and longitude returned will be in decimal.

3. What does getCurrentPosition() returns?
a) latitude
b) longitude
c) direction
d) coordinates
View Answer

Answer: d
Explanation: Coordinates of object is return by getCurrentPosition() method. getCurrentPosition() function accepts three parameters i.e. success, position and error. When data is fetched successfully success callback will be invoked. Lagitude, longitude, direction etc are the properties to be returned.

4. Which of the following technique is not for the mobile browser to identify the location of a user?
a) GPS
b) IP based position
c) WIFI based position
d) A-GPS
View Answer

Answer: b
Explanation: Geolocation API uses the various techniques to identify the location of a user. In desktop browser uses IP bases position technique or WIFI. Mobile browser uses A-GPS, WIFI based position or GPS.

5. Success callback function evoke only when ___________
a) user accepts to share location information
b) always evoke
c) gps is accessible
d) only by mobile browser
View Answer

Answer: a
Explanation: There is a privacy for sharing of user’s location and the callback function is evoke only when a user accepts to share his location. Its input parameter is a position of the object. If this function fails then error callback function will be evoked.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. What timestamp property denotes?
a) time at which WIFI is used
b) the time at which data of the location is retrieved
c) the time at which callback function is evoked
d) current time
View Answer

Answer: b
Explanation: The time at which data of the location is retrieved denoted by timestamp property. This also provides the date. Timestamp is a read-only property.

7. Which of the following is not the property of the ‘cords’ object?
a) Accuracy
b) Altitude
c) AltitudeAccuracy
d) enableHighAccuracy
View Answer

Answer: d
Explanation: cords object has properties like Latitude, longitude, altitude, accuracy, AltitudeAccuracy, speed, heading. Cords.speed defines speed in meters per second. Cords.heading defines degrees clockwise from North.

8. Which parameter gives an accuracy of longitude and latitude?
a) Accuracy
b) AltitudeAccuracy
c) enableHighAccuracy
d) Extra accuracy
View Answer

Answer: a
Explanation: Accuracy of latitude and longitude coordinates is given by ‘accuracy’. It is in meters. Cords.altitudeAccuracy gives altitude accuracy of the position of the object. enableHighAccuracy is a Boolean variable which gives the most accurate position.

9. Which of the following property does not has always a return?
a) coords.longitude
b) coords.latitude
c) coords.accuracy
d) coords.altitude
View Answer

Answer: d
Explanation: coords.latitude is the latitude in decimal number, coords.longitude is the value of longitude in decimal number, coords.altitude returns the value above mean sea level in meters if and only is return is available there.

10. Which property is like the GPS in car?
a) watchPosition()
b) clearWatch()
c) getCurrentPosition()
d) showPosition()
View Answer

Answer: a
Explanation: Current position of the user is returned by watdhPosition(). It update the position os th user as the user moves just like the GPS installed in a car. WatchPosition() method is stopped by clearWatch() method. E.g. if(navigator.geolocation){navigator.watchPosition(showPosition);}

11. Which is not the case of invoking for error callback function?
a) user denies to share the information of a location
b) location information is unavailable
c) request timed out
d) when we are using WIFI
View Answer

Answer: d
Explanation: Error callback function takes the Position Error object as its input parameter. The function is invoked by an unknown error occurred or if the user has denied sharing the information of the location or if the request timed out or if location information is unavailable.

12. What is the default value of timeout?
a) infinity
b) 100
c) 0
d) 1000000
View Answer

Answer: a
Explanation: The value of timeout is positive long value. It specifies the maximum time in milliseconds which the user has taken to respond with the data of the location. Its default value is infinity.

13. maximumAge returns time in _____________
a) nano-seconds
b) milliseconds
c) hour
d) seconds
View Answer

Answer: b
Explanation: The value of maximumAge is positive long. It specifies how long the user can use cached location data before using new location data. When its value is set to zero it indicates the user should not use cached location data and when set to zero is indicates the cached location data must be used by the user.

Sanfoundry Global Education & Learning Series – HTML.

To practice all areas of HTML, here is complete set of 1000+ Multiple Choice Questions and Answers.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.