Giter Site home page Giter Site logo

tiaanduplessis / react-native-google-maps-directions Goto Github PK

View Code? Open in Web Editor NEW
180.0 6.0 28.0 1.36 MB

๐Ÿš• Get direction using Google Maps in React Native ๐Ÿš—

License: MIT License

JavaScript 40.05% TypeScript 59.95%
react-native-app google-maps-api directions

react-native-google-maps-directions's Introduction

๐Ÿšš 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

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

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: "travelmode",
          value: "driving"        // may be "walking", "bicycling" or "transit" as well
        },
        {
          key: "dir_action",
          value: "navigate"       // this instantly initializes navigation using the given travel mode
        }
      ],
      waypoints: [
        {
          latitude: -33.8600025,
          longitude: 18.697452
        },
        {
          latitude: -33.8600026,
          longitude: 18.697453
        },
           {
          latitude: -33.8600036,
          longitude: 18.697493
        }
      ]
    }

    getDirections(data)
  }

  render() {
    return (
      <View style={styles.container}>
        <Button onPress={this.handleGetDirections} title="Get Directions" />
      </View>
    );
  }
}
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:

[
        {
          latitude: -33.8600025,
          longitude: 18.697452,
        },
        {
          latitude: -33.8600026,
          longitude: 18.697453,
        }
]

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.

react-native-google-maps-directions's People

Contributors

aboukinane avatar adaltavo avatar adamliversidge avatar ajdp avatar benhannel avatar donovantc avatar greenkeeper[bot] avatar imgbotapp avatar matan18 avatar renovate-bot avatar tiaanduplessis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-google-maps-directions's Issues

Duplicate code

Hi @tiaanduplessis is see there's a duplicate code in the index file (see attachment). I needed to know what its use is, and if it's an oversight, I am able to do a PR to fix it.

Screenshot 2019-10-03 at 04 48 10

Trying to use custom latitude and longitude value from parameters

I'm trying to set latitude and longitude destination from a value that I had. But it return blank when open up in google maps.

  handleGetDirections = (latitude, longitude) => {
     const data = {
     source: {
       latitude: -8.627666,
       longitude: 115.239225
     },
     destination: {
       latitude: latitude,
       longitude: longitude
     },
     params: [
       {
         key: "dirflg",
         value: "c"
       }
     ]
  };

  getDirections(data);
}

So how I can set a custom latitude and longitude value ?
Thank you.

Not opening in App

I have the latest google maps app installed on iOS (10.3.1)

When using this it still opens the maps link in safari

Allow for empty source

Would it be feasible to allow for empty source so Google Maps opens with the destination pre-filled and let the user specify the source directly in Google Maps?

Typescript support

Nice package!
Is there plans to add a @types package for this to stop TS complaining when it's used?

Unsupported link when using more than one waypoint

RN version: 0.60
Package version: 2.1.1

This is the data I supplay to getDirections method:
const data = { source: { latitude: Number(checkpoints[0].address.lat), longitude: Number(checkpoints[0].address.lng), }, destination: { latitude: Number(checkpoints[numOfCheckpoints - 1].address.lat), longitude: Number(checkpoints[numOfCheckpoints - 1].address.lng), }, params: [ { key: 'travelmode', value: 'driving', // may be "walking", "bicycling" or "transit" as well }, { key: 'dir_action', value: 'navigate', // this instantly initializes navigation using the given travel mode }, ], waypoints: [ { latitude: 39.810355, longitude: -86.135126 }, { latitude: 40.810355, longitude: -86.135126 }, ], }

I'm getting error inside maps: Google maps can't open this link.
When I use only one waypoint it works fine though.

I have my url in log:
'https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination=39.881652%2C-83.057822&origin=41.925685%2C-88.122813&waypoints=39.810355,-86.135126|40.810355,-86.135126'

Auto Start Navigation

I have a requirement that on loading the google map application, have to automatically start the navigation.

Current scenario - It shows the route but user has to click on start to start navigation
I couldn't find any flag associated for the same?

Any idea how could we approach the problem?

It does not take dynamic data from api

handleGetDirections = () => {
const data = {
source: {
latitude: 19.295296,
longitude: -81.382111
},
destination: {
latitude:this.props.customer.latitude,
longitude: this.props.customer.longitude
},
params: [
{
key: "dirflg",
value: "w"
}
]
}
getDirections(data)
}
it is showing the error of Possible Unhandled Promise Rejection (id: 0):
Error: Invalid arguments provided

doesn't show directions

I have installed react-native-google-map-directions version 2.1.1.
I added the following lines in the AndroidManifest.xml file















my code is:
const openMap=(item)=>{
let data={
destination:{
latitude:item.latitude,
longitude:item.longitude
},
params:[{
key:"travelmode",
value:"driving"
}],
waypoints:[]
}
getDirections(data)
}
let renderRandomMarkers=locations.map((item,key)=>(

    <Marker key={key} image={require('../assets/image/pin.png')}  coordinate={{longitude:item.longitude,latitude:item.latitude}}>
        <Callout onPress={()=>openMap(item)}>
            <View style={{flexDirection:'row'}}>
                <Text>Location :</Text>
                <Text>{item.latitude + ',' + item.longitude}</Text>
            </View>
        </Callout>
    </Marker>
))

when click the callout maps is opened, but it showing like this
WhatsApp Image 2022-10-17 at 4 13 53 AM
Pls help me

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.