I'm making a mobile page where a user who needs a quick way to copy an address so they can open their preferred maps app.
Other solutions like selecting the whole address to copy manually or using "if apple/android user click this" are all I can think of using, but I want to avoid. I need an all-device, compatible solution and JS is a friend to all.
Here is the best method that i adapted from this answer: https://stackoverflow.com/a/18899718/2887660
function openAddress(){
// If it's an iPhone..
if( (navigator.platform.indexOf("iPhone") != -1)
|| (navigator.platform.indexOf("iPod") != -1))
window.open("maps://maps.google.com/maps?daddr=lat,long&ll=");
else
window.open("http://maps.google.com/maps?daddr=lat,long&ll=");
}
html
<p>123 Example Road</p>
<a onclick="openAddress()">Touch to Copy Address</a>