I am faced with a situation where the user does not want to allow the system to use the google location api to center the map on them.
I need to set a default v
Yes there is! Google maps uses navigator.geolocation.getCurrentPosition() method to get your current location. This method allows a success callback (when a user says yes) and error callback (when user says no). It is also good to check if the browser supports geolocation. The following shows how to use it
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(hasGeolocation, noGeolocation)
} else {
geolocationNotSupported();
}
function hasGeolocation() {
console.log("yeah!")
}
function noGeolocation() {
console.log("user said no!")
}
function geolocationNotSupported() {
console.log("this browser does not support geolocation")
}
There is also an example on google maps api docs to show this in context of google maps usage https://developers.google.com/maps/articles/geolocation