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
Asked
Active
Viewed 2,179 times
0
-
1can you tell me whats not working properly? – Gaurav Roy Sep 09 '22 at 04:35
-
Does this answer your question? [open maps/google maps in react native](https://stackoverflow.com/questions/43214062/open-maps-google-maps-in-react-native) – Waleed Sep 09 '22 at 04:44
3 Answers
1
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);
};

Waleed
- 1,097
- 18
- 45
0
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

Brandon Pelton-Cox
- 138
- 8
0
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

Gaurav Roy
- 11,175
- 3
- 24
- 45