Walk Score

Walk Score

  • Category: Geocoding


Using Walk Score's Travel Time API with JavaScript

Walk Score's Travel Time API allows developers to calculate travel times and distances for driving, walking, biking, and public transportation between two points. This API can be particularly useful for applications that provide directions or recommendations for things like restaurants or events. In this post, we'll explore how to use the Travel Time API with JavaScript.

Before we begin

Before using the Travel Time API, developers must create an account with Walk Score and obtain an API key. The API key is used to authenticate requests and should be kept confidential.

Getting started

To start using the Travel Time API with JavaScript, you'll need to make a request using the HTTP GET method. The endpoint for the API is: https://api.walkscore.com/traveltime/?

The Travel Time API requires several parameters to be passed in the request URL. These parameters include:

  • origin: The starting location for the travel time calculation.
  • destination: The destination location for the travel time calculation.
  • mode: The mode of transportation to use in the calculation. Values can be drive, walk, bike, or transit.
  • time: The time at which the travel time should be calculated. This must be in UNIX timestamp format.
  • api_key: The API key obtained from Walk Score.

Example code

Below is some example code that demonstrates how to use the Travel Time API in JavaScript. In this example, we'll calculate the travel time and distance between the Empire State Building in New York City and the White House in Washington, D.C., for driving, walking, biking, and public transportation using the Travel Time API.

const apiKey = 'YOUR_API_KEY_HERE';
const origin = 'Empire State Building, New York, NY';
const destination = 'The White House, Washington, D.C.';
const time = Math.floor(Date.now() / 1000); // Current time in UNIX timestamp format

const modes = ['drive', 'walk', 'bike', 'transit'];
modes.forEach((mode) => {
    const url = `https://api.walkscore.com/traveltime/?origin=${encodeURIComponent(origin)}&destination=${encodeURIComponent(destination)}&mode=${mode}&time=${time}&api_key=${apiKey}`;
    fetch(url)
        .then((response) => response.json())
        .then((data) => {
            console.log(`Travel time for ${mode}: ${data.duration} minutes`);
            console.log(`Distance for ${mode}: ${data.distance} miles`);
        })
        .catch((error) => {
            console.error('Error calculating travel time.', error);
        });
});

In this example, we first define our API key, starting location, and destination location. We then calculate the current time in UNIX timestamp format, which is a required parameter for the Travel Time API. Next, we define an array of the four different modes of transportation (driving, walking, biking, and public transit) that we want to calculate travel times for.

We then loop through each mode of transportation in the modes array and construct a URL for the API request. We use the encodeURIComponent function to safely encode the origin and destination parameters in the URL.

We then use the fetch function to make the API request and return the results as JSON. Finally, we log the travel time and distance for each mode of transportation to the console.

Conclusion

With Walk Score's Travel Time API, developers can easily calculate travel times and distances between two points for different modes of transportation. By using JavaScript, developers can integrate this functionality into their web applications.

Visit to Walk Score website

Similar APIs of Geocoding

IPGeolocation API

IPGeolocation API

Geocoding

ipgeolocation.io API provides IP to Location information such as country, city, state, province, latitude and longitude, company detail, ISP lookup, threat intelligence information, tor, VPN and proxy data. It also provides user agent lookup information, sun rise, sun set and moon set, moon rise timings. All APIs support REST JSON and XML formats.

IPGeoIPIP

Abstract Geolocation API

Abstract Geolocation API

Geocoding

Abstract IP geolocation API provides developers from small startups to big technology companies with a fast and robust API to get the location of any IP worldwide. With Abstract, you can get the city, region and country of any IP. In addition, Abstract IP Geolocation API provides you with timezone and coordinates data so you can build the most delightful experience for your developers. Whether it's for content personalisation, fraud detection or GDPR compliance, Abstract covers a variety of use cases thanks to its extensive and robust platform currently used by 100,000 developers worldwide in companies like Google or Shopify. Freelancers and indiehackers can enjoy an extensive free plan serving up to 20,000 calls per month.

ipgeolocationip

Geocodify

Geocodify

Geocoding

Worldwide geocoding, geoparsing and autocomplete for addresses.

geocodingaddressapi

ArcGIS World Geocoding Services

ArcGIS World Geocoding Services

Geocoding

The World Geocoding Service finds addresses and places from a single endpoint.

geocodingmappingarcgis

Geolake

Geolake

Geocoding

Easy to use geocoding API with best-in-class accuracy. Provides both API based geocoding as well as via CSV batch upload. Can return ZIP+4 values for US addresses, geocode IP addresses and phone numbers based on the data that is available. Data returned may include the top level domain for a country, currency and time zone for the location.

geocodegeocodergeolake

IP Geolocation API

IP Geolocation API

Geocoding

Free IP Geolocation and IP Address Lookup Location API.

ipgeocodingapi

Maps Me

Maps Me

Geocoding

API is designed to allow integrating the offline maps with your iOS or Android app. The best part is that MAPS.ME code is completely open, and you can hack it to your needs!

ipgeocodingapi

IP Api

IP Api

Geocoding

Find location with ip address

ipgeocodingapi

International Street Address API

International Street Address API

Geocoding

Convert addresses into proper USPS or international address format

streetaddressip

IP Geolocation

IP Geolocation

Geocoding

Free IP API provides country, city, state, province, local currency, latitude and longitude, company detail, ISP lookup, language, zip code, country calling code, time zone, current time, sunset and sunrise time, moonset and moonrise time from any IPv4 and IPv6 address in REST, JSON and XML format over HTTPS.

ipgeolocationcity