Skip Navigation

[Resolved] A link that opens the Phone's Google/Apple Maps app

This support ticket is created 4 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by maxfieldB 4 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1461385

Tell us what you are trying to do?
Hello, on the detail pages of each class on this website, I'd like to have a link that opens the address in the user's app app. Do you have anything like this?

Is there any documentation that you are following?
https://stackoverflow.com/questions/9688607/how-to-open-a-mobile-devices-map-app-when-a-user-clicks-on-a-link/10632079

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1461897

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

There are a few parts to this.

You need to output map links that include the addresses from your address custom field as query parameters in the correct format, but you need to output different links depending on whether your users are visiting on Apple devices or Android devices.

I looked at the stackoverlow article you shared, and it appears that much of the information is probably out of date. I'm taking an example from there, but you will need to perform your own research as to what the current requirements are.

Here's an example of the alternate formats required (not tested):

<a href='<em><u>hidden link</u></em>;
    Open in google maps
</a>
<a href='<em><u>hidden link</u></em>;
    Open in apple maps
</a>

Note how the address is URL encoded (e.g. spaces are converted to %20).

That's the only part I can help you with, really.

You could register a custom shortcode to urlencode any content inside the shortcode, e.g.

add_shortcode('urlencode', function ($atts = [], $content = null) {

    $return = urlencode( $content );

    return $return;
});

Then, when generating a link such as those above where the address comes from some custom field, you could use the urlencode shortcode like so:

<a href='<em><u>hidden link</u></em> field='my-address'][/types][/urlencode]'>

But that leaves

1. displaying different links according to which device is being used, and
2. confirming the required format of the links to open the apps in question

You will need to do some research for 2.

For 1, you will need to perform some browser sniffing to detect the device and use the results to hide one of the links.

So, you could add classes to the links, e.g. "ios" and "android", then write some JavaScript the checked the navigation object to determine the device and then hide links which have the class of the other device.

It's outside of support to write such code for you, but if you try yourself and get stuck let me know and I'll see if I can help.

#1473845

Thanks Nigel - this is really a lot of info - I appreciate you taking the time to look into this.

It looks like this is going to be out of scope for us based on your reply. Thanks again - very much appreciated!

Max