I have a page that contains a code that gets the current location from the device and load other stuff based on the location with this code:
if (navigator.ge
GeoLocation works only if a user provides his/her permissions.
Make sure that is the case.
This CodePen demo has been tested in iOS simulator with Safari and successfully shown the latitude and the longitude.
var options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0
};
function log(data) {
const tag = document.createElement('p');
tag.textContent = data;
document.body.appendChild(tag);
}
function success(pos) {
var crd = pos.coords;
console.log('Successfully determined a user position:', crd);
log('Your current position is:');
log(`Latitude : ${crd.latitude}`);
log(`Longitude: ${crd.longitude}`);
log(`More or less ${crd.accuracy} meters.`);
}
function error(err) {
console.warn(`ERROR(${err.code}): ${err.message}`);
}
navigator.geolocation.getCurrentPosition(success, error, options);
It can't be the case if your code doesn't hit either if
nor else
unless some other code has triggered an infinite loop earlier in your code.