react-native-distance

Google's Distance Matrix API wrapper for React Native

Usage no npm install needed!

<script type="module">
  import reactNativeDistance from 'https://cdn.skypack.dev/react-native-distance';
</script>

README

react-native-distance Build Status

Google's Distance Matrix API wrapper for React Native

Install

$ npm install react-native-distance

Usage

const distance = require('react-native-distance');

(async () => {
  const res = await distance({ 
    units: 'imperial', 
    origins: 'Washington, DC', 
    destinations: 'New + York + City, NY', 
    key: 'GOOGLE_KEY',
}); 

console.log(res);

You will get as response

{
  "destination_addresses": [
    "New York, NY, USA"
  ],
  "origin_addresses": [
    "Washington, DC, USA"
  ],
  "rows": [
    {
      "elements": [
        {
          "distance": {
            "text": "226 mi",
            "value": 363999
            },
            "duration": {
              "text": "3 hours 50 mins",
              "value": 13777
            },
            "status": "OK"
        }
      ]
    }
  ],
  "status": "OK"
}

License

MIT © Abraham Hernandez