I mean, if i have a button on the web page, when a user click the button,
then can get the user's geolocation information.
but before, the browser will ask the user whether accept to use the geolocation service.
if the user reject the geolocation service, can i get the reject event?
The Navigator. geolocation read-only property returns a Geolocation object that gives Web content access to the location of the device. This allows a Web site or app to offer customized results based on the user's location.
You can go for an external service like https://www.geolocation-db.com. They provide a geolocation service based on IP addresses where you don't need user permission.
The Geolocation. getCurrentPosition() method is used to get the current position of the device.
The HTML Geolocation API is used to get the geographical position of a user.
Yes.
Example:
navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
function successCallback(){
alert('Thanks for allowing geolocation!');
}
function errorCallback(){
alert('You denied us access to geolocation...');
}
Check Geolocation API Specification for further reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With