0

I'm developing a react-native mobile app an I would like to send an intent (geo: ...) specifically to google map app. In this native example they use the Intent.setPackage() function, but I can not find a similar solution for react-native.

Here's my code that currently let the user choose between possible apps. I would like that only google maps app manages the intent.

<Text
  style={{ textDecorationLine: 'underline', color: PURPLE }}
  onPress={async () => {
    const scheme = Platform.select({ ios: 'maps:0,0?q=', android: 'geo:0,0?q=' });
    const latLng = `${item.latitude},${item.longitude}`;
    const label = item.address;
    const url = Platform.select({
      ios: `${scheme}${label}@${latLng}`,
      android: `${scheme}${latLng}(${label})`
    });
    const supported = await Linking.canOpenURL(url);
    if (supported) {
      await Linking.openURL(url);
    } else {
      Alert.alert(`Don't know how to open current address`);
      console.log('error opening link', url);
    }
  }
  }
>
  {context.translations.GO_TO_MAPS}
</Text>

Thanks for helping

  • Does this answer your question? [open maps/google maps in react native](https://stackoverflow.com/questions/43214062/open-maps-google-maps-in-react-native) – MrUpsidown Oct 04 '22 at 14:48
  • Unfortunately no. My objective is to make only google maps catch the intent With the current approach (and the one you suggested) android will show to the user all the possible apps that can manage the intent, and let the user choose which use – Alessandro Salvetti Oct 04 '22 at 20:33

1 Answers1

0

I am not sure this will help you or not, but i use this to open address in google

if(Platform.OS === 'ios'){
  Linking.openURL(`maps://app?saddr=${latitude}+${longitude}&daddr=${parseFloat(latitude)}+${parseFloat(longitude)}`)
} else{
 Linking.openURL(`google.navigation:q=${parseFloat(latitude)}+${parseFloat(longitude)}`)
}
The Scalion
  • 130
  • 6
  • 1
    Thanks for helping. Unfortunately, also in this way you are letting the user decide which app to use. For example if you have installed both google maps and waze, then android will ask you to choose the app in which open the navigation – Alessandro Salvetti Oct 05 '22 at 07:37