Geolocation
Geolocation is the art of figuring out where you are in the world and (optionally) sharing that information with people you trust. There are many ways to figure out where you are—your IP address, your wireless network connection, which cell tower your phone is talking to, or dedicated GPS hardware that receives latitude and longitude information from satellites in the sky.
Checking for geolocation support uses detection technique #1
(see Detection Techniques). If your browser supports
the geolocation API, there will be a geolocation property on the global navigator object. If your browser doesn’t
support the geolocation API, the geolocation property will be undefined. Here’s
how to check for geolocation support:
function supports_geolocation() {
return !!navigator.geolocation;
}Instead of writing this function yourself, you can use Modernizr (see Modernizr: An HTML5 Detection Library) to detect support for the geolocation API:
if (Modernizr.geolocation) { // let's find out where you are! } else { // no native geolocation support ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access