Open Maps with predefined route

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.

1 Like

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

1 Like

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

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

2 Likes

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