Home > Net >  How to open google map with latitude and longitude
How to open google map with latitude and longitude

Time:09-09

I have latitude and longitude values and on click of direction icon I want to open map with marker and if map application is not available in phone then want to navigate to play store, please let me know how can I achieve this

CodePudding user response:

I would recommend you use the expo-linking package. Check the docs for instructions on how to install and use. Even if you don't use Expo yet, you can use their SDKs by adding their base package (see this). As the docs say, if you want the additional functionality of directing the user to the Play store if Google Maps is not installed, you'll also need the react-native-app-link package.

Once you have the package installed you'll need to use the linking scheme provided by Google Maps, as described here

CodePudding user response:

as per Narevs answer in another post

You can try this below

const scheme = Platform.select({ ios: 'maps:0,0?q=', android: 'geo:0,0?q=' });
const latLng = `${lat},${lng}`;
const label = 'Custom Label';
const url = Platform.select({
  ios: `${scheme}${label}@${latLng}`,
  android: `${scheme}${latLng}(${label})`
});

    
Linking.openURL(url);

Hope it helps. feel free for doubts

CodePudding user response:

You can use the geo/maps link like this:

  const openAddressOnMap = (label, lat, lng) => {
    const scheme = Platform.select({
      ios: 'maps:0,0?q=',
      android: 'geo:0,0?q=',
    });
    const latLng = `${lat},${lng}`;
    const label = label;
    const url = Platform.select({
      ios: `${scheme}${label}@${latLng}`,
      android: `${scheme}${latLng}(${label})`,
    });
    Linking.openURL(url);
  };
  • Related