Get to know MDN better
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The location event of the HTMLGeolocationElement interface is fired whenever the browser receives location data, or error information when a location data request was unsuccessful.
Use the event name in methods like addEventListener(), or set an event handler property.
An Event.
In our Embedded map demo (source code), we use a location event handler to respond to location data and errors being received:
If location data is returned successfully, we access it via the HTMLGeolocationElement.position property, and retrieve the latitude and longitude values. We log those to the console, then plot them on a map by passing them into the drawMap() function along with a reference to the HTMLGeolocationElement object. If the data request fails, we access the error via the HTMLGeolocationElement.error property and log the error message to the console.
See the main HTMLGeolocationElement page for a full walkthrough of this example.
| The HTML Geolocation Element # dom-htmlgeolocationelement-onlocation |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Feb 13, 2026 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.