HTML and CSS Reference
In-Depth Information
document.getElementById('coords').innerHTML = "<p><strong>lat: </strong>" + lat + "
<br><strong>long: </strong>" + long + "";
}
function error(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert("user did not share geolocation data");
break;
case error.POSITION_UNAVAILABLE:
alert("could not detect current position");
break;
case error.TIMEOUT:
alert("retrieving position timed out");
break;
default:
alert("unknown error");
break;
}
}
function adInit(event) {
console.log(event.type)
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
}
window.addEventListener('DOMContentLoaded', adInit, false);
</script>
</body>
</html>
As you can see from the previous code sample, you check the navigator.geolocation object, and if it's true, you
know that the Geolocation API is supported in your browser or device. After that, you call navigator.geolocation.
getCurrentPosition and pass in two arguments, which are a success callback function and an error callback function.
Once you run this command, the user will notice the previous prompt's outline, and the user will need to take the
necessary action. Assuming they select allow, it will run through the success method; otherwise, it will run through the
error method, and you can handle why the error occurred by looking at the error code you receive in your callback.
Once the user allows the sharing of their location, you can grab the latitude and longitude values from the position
object that comes with the success callback. With this location information, you can tie it to location-based services
or geocode the latitude/longitude into a ZIP code to query against services like Yahoo's weather service or Google's
mapping services. The bottom line is that geolocation provides some rich experiences within the ad environment.
Geolocation in Advertising
Location is a big part of advertising on the Web. As you are aware, advertisers want to target users by as many ways
necessary to ensure a good ROI on their media investment. With this new API, developers can do just that! This location
information is hugely beneficial when pairing with mapping services such as Google, Apple, or Bing or when you want to
locate a user and navigate them to the nearest retail store by offering them detailed directions to get them into the store.
 
Search WWH ::




Custom Search