Skip to content

Instantly share code, notes, and snippets.

@macariojames
Last active October 29, 2018 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macariojames/c4c1136e1015b410119998f6274bf1ea to your computer and use it in GitHub Desktop.
Save macariojames/c4c1136e1015b410119998f6274bf1ea to your computer and use it in GitHub Desktop.
Link opens Google Maps, iOS Maps on mobile device; normal browser link otherwise (jQuery)
// Checks if on mobile device
// Changes link to go to Google Maps
// Which should open automatically in Apple or Google Maps on Android/iOS device ~mj
function mobileMapClicker() {
console.log(navigator.userAgent);
// Checks userAgent if mobile device
if (/Mobi/.test(navigator.userAgent)) {
console.log('Mobile Device Detected!');
/* if we're on iOS, open in Apple Maps */
var iOS = /iPad|iPad Simulator|iPhone|iPhone Simulator|iPod|iPod Simulator/.test(navigator.userAgent) && !window.MSStream;
// sets true or false if iPad, iPhone, iPad or their simulators ~mj
if (iOS) {
console.log("iOS Device");
$('.phc-address').attr("href", "maps://www.google.com/maps?ll=39.985891,-75.086443&z=14&t=m&hl=en-US&gl=US&mapclient=embed&cid=17254388161361260698")
} else {
// otherwise, serve normal google maps link
// let the device choose if it opens maps app
console.log('Not iOS!');
$('.phc-address').attr("href", "https://www.google.com/maps?ll=39.985891,-75.086443&z=14&t=m&hl=en-US&gl=US&mapclient=embed&cid=17254388161361260698");
}
} else {
console.log('Desktop');
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment