Create an onClick function for address that opens maps

Hey friends, hoping you can help me with some code. Should be simple but I can’t figure it out.

I’m creating a CRM for my company. The CRM displays projects my company is working on. Each project has a dynamic page. On that dynamic page is a text element that’s linked to the customers property address using the native Wix Dataset connections, not through code. I want to create an onClick event for this text element that provides a link that directs the user to get directions to the address on the device they’re using.

For example, a click event from a PC or Mac computer might open google maps in a new tab. A click event from an android device might open the Google maps app. A click event from an iOS device would ideally open the Apple Maps app, or whichever maps app is set as the default application for that users iOS device as I believe this setting can be changed.

I did find a tech sheet explaining how to dynamically create an Apple Maps link that automatically starts directions. This link would likely default to opening the Apple Maps app on an iOS device. I’m sure Google has a similar tech sheet on how to format a google maps link, though I haven’t looked at it yet.

Am I thinking of this problem the correct way? I imagine I would have two dynamic links, for Apple Maps and Google Maps, and the click event would direct the user to the appropriate link based on the operating system or device type. Is that correct logic, or is there a better way of doing this?

If that is correct, how do I go about determining the device type and setting up the conditional formatting in Wix code?

I’m using Wix Studio editor.

I’ve attached a screenshot from an iOS device for visual reference.

A little bit more research taught me that clicking an Apple Maps link on an android device will open the Google Maps equivalent automatically, so there is no need to distinguish between device types.

I swapped the text element out for a button. Then I created a data hook that generates the Apple Maps link based on the project address and store the link in a URL field I’ve titled ‘appleMapsUrl’ in the collection. Then I just set the button link to the url field and it’s label to the address field using the dataset connections.

If anyone can think of a better solution I’d still love to hear it.