Geography
Our HTML5 library comes with a set of functions for geospacial operations like distance calculations and finding the nearest point in a list of locations.
To make use of our geospacial functions you must specify "$latitude"
and "$longitude"
as variables in your manifest.json
file:
"variables": {
"$latitude": "{{latitude}}",
"$longitude": "{{longitude}}"
}
The following example creates a <div>
element and sets its text content to the browser's nearest city from a list of locations.
<script type="text/javascript">
html5.ready(function() {
var coords = [
{latitude: 55.6761, longitude: 12.5683, city: "Copenhagen"},
{latitude: 60.1708, longitude: 24.9375, city: "Helsinki"},
{latitude: 59.3294, longitude: 18.0686, city: "Stockholm"},
{latitude: 59.9500, longitude: 10.7500, city: "Oslo"}
];
var closestCity = html5.geo.nearest(coords).city;
document.getElementById("city").innerHTML = closestCity;
});
</script>
<p>City: <span id="city">...</span></p>
To test other locations than your own web browser simply set the geo location yourself in your manifest.json
file. Don't forget to reset the variables to the correct macros before submitting the ad to our system.
"variables": {
"$latitude": 59.3294,
"$longitude": 18.0686
}
Please read our JavaScript Reference for information about available geospacial functions.
Last modified: Mon Sep 23 2024 11:48:54 GMT+0200 (Central European Summer Time)