项目作者: tiaanduplessis

项目描述 :
🚕 Get direction using Google Maps in React Native 🚗
高级语言: JavaScript
项目地址: git://github.com/tiaanduplessis/react-native-google-maps-directions.git
创建时间: 2017-02-16T14:21:43Z
项目社区:https://github.com/tiaanduplessis/react-native-google-maps-directions

开源协议:MIT License

下载


🚚 react-native-google-maps-directions 🚲

🚕 Get direction using Google Maps in React Native 🚗

Greenkeeper badge
npm version
Downloads
Standard
Travis Build

Table of Contents

About

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.

Install

  1. $ npm install --save react-native-google-maps-directions
  1. $ yarn add react-native-google-maps-directions

Usage

  1. import getDirections from 'react-native-google-maps-directions'
  2. export default class gmapsDirections extends Component {
  3. handleGetDirections = () => {
  4. const data = {
  5. source: {
  6. latitude: -33.8356372,
  7. longitude: 18.6947617
  8. },
  9. destination: {
  10. latitude: -33.8600024,
  11. longitude: 18.697459
  12. },
  13. params: [
  14. {
  15. key: "travelmode",
  16. value: "driving" // may be "walking", "bicycling" or "transit" as well
  17. },
  18. {
  19. key: "dir_action",
  20. value: "navigate" // this instantly initializes navigation using the given travel mode
  21. }
  22. ],
  23. waypoints: [
  24. {
  25. latitude: -33.8600025,
  26. longitude: 18.697452
  27. },
  28. {
  29. latitude: -33.8600026,
  30. longitude: 18.697453
  31. },
  32. {
  33. latitude: -33.8600036,
  34. longitude: 18.697493
  35. }
  36. ]
  37. }
  38. getDirections(data)
  39. }
  40. render() {
  41. return (
  42. <View style={styles.container}>
  43. <Button onPress={this.handleGetDirections} title="Get Directions" ></Button>
  44. </View>
  45. );
  46. }
  47. }

Demo usage

API

The module exports a single getDirections function that takes a object as its argument. The object may have destination (Where you’re going to) and source (Where you’re coming from) both of which have latitude and longitude number properties. If source is undefined, it defaults to the user’s current location. If destination is undefined, it leaves it blank in Google Maps and the user will be able to enter a destination.

Additionaly parameters can be added as key-value pairs to the params array (optional). The supported parameters are listed here.

Waypoints

Waypoints should be passed as an array of objects:

  1. [
  2. {
  3. latitude: -33.8600025,
  4. longitude: 18.697452,
  5. },
  6. {
  7. latitude: -33.8600026,
  8. longitude: 18.697453,
  9. }
  10. ]

Contribute

Contributions are welcome. Please open up an issue or create PR if you would like to help out.

Note: If editing the README, please conform to the standard-readme specification.

License

Licensed under the MIT License.