Skip to content

Instantly share code, notes, and snippets.

@pjaudiomv
Last active April 11, 2026 19:01
Show Gist options
  • Select an option

  • Save pjaudiomv/5497def3095aa00411c4dca5173231f8 to your computer and use it in GitHub Desktop.

Select an option

Save pjaudiomv/5497def3095aa00411c4dca5173231f8 to your computer and use it in GitHub Desktop.
Platform-aware directions URL helper
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