Here is the start of some JavaScript to handle a list of waypoints and trigger something within 10m. Polling is every 10 seconds:
Code:
// Define your waypoints
const waypoints = [
{ lat: 51.5074, lng: -0.1278 }, // Example coordinates
// Add the rest of your waypoints here
];
// Function to check proximity to waypoints
function checkProximity(position, waypoints) {
waypoints.forEach((waypoint, index) => {
const distance = google.maps.geometry.spherical.computeDistanceBetween(
new google.maps.LatLng(position.coords.latitude, position.coords.longitude),
new google.maps.LatLng(waypoint.lat, waypoint.lng)
);
if (distance < 10) {
// Trigger your custom event here
console.log(`Within 10m of waypoint ${index}`);
}
});
}
// Watch the user's position
navigator.geolocation.watchPosition(
(position) => {
// Update map center
map.setCenter(new google.maps.LatLng(position.coords.latitude, position.coords.longitude));
// Check proximity to waypoints
checkProximity(position, waypoints);
},
(error) => {
console.error(error);
},
{
maximumAge: 10000,
timeout: 10000,
enableHighAccuracy: true,
}
);
All you have remaining is create a container for the map, add all your waypoints and trigger a pop-up layer of the associated postcard.
Then you have to work out how a layer can be programmatically opened. What to do if the viewer closes the layer. Does it re-open? Can if be invoked after they've left the location?
Acorn
Bookmarks