-2

In my react native applications .Once user presses button in my application, I would like to open standard Google Map application and to show particular location. How can I do it

  • Does this answer your question? [open maps/google maps in react native](https://stackoverflow.com/questions/43214062/open-maps-google-maps-in-react-native) – Harshal Valanda Feb 24 '20 at 05:16

2 Answers2

0

SOLUTION

openGps = (lat, lng) => {
  var scheme = Platform.OS === 'ios' ? 'maps:' : 'geo:';
  var url = scheme + `${lat},${lng}`;
  Linking.openURL(url);
}

Pass latitude and longitude accordingly

Or if you want with custom label try this :

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);
Akila Devinda
  • 5,054
  • 3
  • 19
  • 35
0

Install 'react-native-navigation-directions' and the use the below give code. call _callShowDirections on click of your button, it will redirect you to the standard google map application.

import { OpenMapDirections } from 'react-native-navigation-directions';

//Use this function 
  _callShowDirections = () => {
     const startPoint = {
       longitude: 'START_POINT_LONGITUDE',
       latitude: 'START_POINT_LATITUDE'
     } 

     const endPoint = {
       longitude: 'END_POINT_LONGITUDE',
       latitude:  'END_POINT_LATITUDE'
     }

    const transportPlan = 'd';

    OpenMapDirections(startPoint, endPoint, transportPlan).then(res => {
      console.log(res)
    });
  }
Kailash
  • 777
  • 4
  • 19