Locations added
This commit is contained in:
8
frontend/lib/formatLocation.ts
Normal file
8
frontend/lib/formatLocation.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Location } from "@/types/types";
|
||||
|
||||
// Helper to format location as a string
|
||||
const formatLocation = (location: Location): string => {
|
||||
return `${location.street}, ${location.city}, ${location.postalCode}`;
|
||||
};
|
||||
|
||||
export default formatLocation;
|
||||
28
frontend/lib/openNavigationMap.ts
Normal file
28
frontend/lib/openNavigationMap.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
const openNavigationApp = (
|
||||
location: string,
|
||||
latitude?: number | null,
|
||||
longitude?: number | null,
|
||||
) => {
|
||||
if (latitude && longitude) {
|
||||
const googleMapsUrl = `https://www.google.com/maps/dir/?api=1&destination=${latitude},${longitude}`;
|
||||
const appleMapsUrl = `maps://maps.apple.com/?daddr=${latitude},${longitude}`;
|
||||
const isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||
if (isIOS) {
|
||||
window.open(appleMapsUrl, "_blank");
|
||||
} else {
|
||||
window.open(googleMapsUrl, "_blank");
|
||||
}
|
||||
} else {
|
||||
const encodedAddress = encodeURIComponent(location);
|
||||
const googleMapsUrl = `https://www.google.com/maps/dir/?api=1&destination=${encodedAddress}`;
|
||||
const appleMapsUrl = `maps://maps.apple.com/?q=${encodedAddress}`;
|
||||
const isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
||||
if (isIOS) {
|
||||
window.open(appleMapsUrl, "_blank");
|
||||
} else {
|
||||
window.open(googleMapsUrl, "_blank");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default openNavigationApp;
|
||||
11
frontend/lib/osmEmbed.ts
Normal file
11
frontend/lib/osmEmbed.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// Construct OSM embed URL
|
||||
const getOsmEmbedUrl = (lat: number, lon: number) => {
|
||||
const delta = 0.005; // Adjust zoom level
|
||||
const minLon = lon - delta;
|
||||
const minLat = lat - delta;
|
||||
const maxLon = lon + delta;
|
||||
const maxLat = lat + delta;
|
||||
return `https://www.openstreetmap.org/export/embed.html?bbox=${minLon},${minLat},${maxLon},${maxLat}&marker=${lat},${lon}&layer=mapnik`;
|
||||
};
|
||||
|
||||
export default getOsmEmbedUrl;
|
||||
Reference in New Issue
Block a user