Open Maps with predefined route

#1

Hi! o/

I’m using maplink API to create route between two or more points. I can show the route in react-native-maps, but can I open default map apps (Apple Maps or Google Maps) with predefined route?

Like this:
User search route > App show route > User click in button > Open Google Maps with the route previous defined.

0 Likes

#2

Hey @dobrado,

If I understand your question correctly, you can implement it like this:

_handlePressDirections = () => {
    let { address, postalCode, city } = this.props.userRoute;

    let daddr = encodeURIComponent(`${address} ${postalCode}, ${city}`);

    if (Platform.OS === 'ios') {
      Linking.openURL(`http://maps.apple.com/?daddr=${daddr}`);
    } else {
      Linking.openURL(`http://maps.google.com/?daddr=${daddr}`);
    }
  };
}

Cheers,

Adam

0 Likes

#3

Wow! I get it. I thought there was some method to open these apps.

Thanks Adam, you helped me a lot! :slight_smile:

1 Like

closed #4

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

0 Likes