Which code segment should you use?

You are developing a website that helps users locate theaters in their area from a browser.
You created a function named findTheaters ().
The function must:
Get the current latitude and longitude of the user’s device
Pass the user’s location to findTheaters()
The user needs to access the geolocation information from the browser before searching for
theaters.
Which code segment should you use?

You are developing a website that helps users locate theaters in their area from a browser.
You created a function named findTheaters ().
The function must:
Get the current latitude and longitude of the user’s device
Pass the user’s location to findTheaters()
The user needs to access the geolocation information from the browser before searching for
theaters.
Which code segment should you use?

A.
Option A

B.
Option B

C.
Option C

D.
Option D



Leave a Reply 2

Your email address will not be published. Required fields are marked *


abdullah tahan

abdullah tahan

ANSWER : C

Click the button to get your coordinates.

Try It

var x = document.getElementById(“demo”);

function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(hasposition, noposition);
} else {
x.innerHTML = “Geolocation is not supported by this browser.”;
}
}

function hasposition(position) {
x.innerHTML = “Latitude: ” + position.coords.latitude +
“Longitude: ” + position.coords.longitude;
}

function noposition(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = “User denied the request for Geolocation.”
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = “Location information is unavailable.”
break;
case error.TIMEOUT:
x.innerHTML = “The request to get user location timed out.”
break;
case error.UNKNOWN_ERROR:
x.innerHTML = “An unknown error occurred.”
break;
}
}