Get Directions Using Google Map In React Native

Category: Others , React Native | November 27, 2017
Author: tiaanduplessis
Views Total: 899
Official Page: Go to website
Last Update: November 27, 2017
License: MIT

A tiny module that uses the React Native Linking API to get directions using Google Maps by opening it in the default browser or app if installed.

Installation:

# Yarn
$ yarn add react-native-google-maps-directions

# NPM
$ npm install react-native-google-maps-directions --save

Usage:

import getDirections from 'react-native-google-maps-directions'

export default class gmapsDirections extends Component {

  handleGetDirections = () => {
    const data = {
       source: {
        latitude: -33.8356372,
        longitude: 18.6947617
      },
      destination: {
        latitude: -33.8600024,
        longitude: 18.697459
      },
      params: [
        {
          key: "dirflg",
          value: "w"
        }
      ]
    }

    getDirections(data)
  }

  render() {
    return (
      <View style={styles.container}>
        <Button onPress={this.handleGetDirections} title="Get Directions" />
      </View>
    );
  }
}

Preview:

Get Directions Using Google Map In React Native