Last active
April 11, 2026 19:01
-
-
Save pjaudiomv/5497def3095aa00411c4dca5173231f8 to your computer and use it in GitHub Desktop.
Platform-aware directions URL helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export type Platform = 'web' | 'ios' | 'android'; | |
| export function getPlatform(): Platform { | |
| if (typeof window === 'undefined') return 'web'; | |
| const ua = window.navigator.userAgent.toLowerCase(); | |
| if (/android/.test(ua)) return 'android'; | |
| if (/iphone|ipad|ipod/.test(ua) || (window.navigator.platform === 'MacIntel' && window.navigator.maxTouchPoints > 1)) return 'ios'; | |
| return 'web'; | |
| } | |
| export function getDirectionsUrl(location: Location): string { | |
| const lat = location.latitude; | |
| const lng = location.longitude; | |
| const platform = getPlatform(); | |
| if (platform === 'ios') { | |
| return `maps://?daddr=${lat},${lng}`; | |
| } else if (platform === 'android') { | |
| return `geo:${lat},${lng}?q=${lat},${lng}`; | |
| } | |
| return `https://www.google.com/maps/dir/?api=1&destination=${lat},${lng}`; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment