<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: tomastraveltime</title>
    <description>The latest articles on DEV Community by tomastraveltime (@tomasitraveltime).</description>
    <link>https://dev.to/tomasitraveltime</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F160944%2F2b129a90-dff1-49be-8f0f-37366f3af187.jpg</url>
      <title>DEV Community: tomastraveltime</title>
      <link>https://dev.to/tomasitraveltime</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tomasitraveltime"/>
    <language>en</language>
    <item>
      <title>Drawing a drive time polygon on a Google Map: how far you can go in 1 hour or more?</title>
      <dc:creator>tomastraveltime</dc:creator>
      <pubDate>Wed, 16 Sep 2020 12:17:36 +0000</pubDate>
      <link>https://dev.to/tomasitraveltime/drawing-a-drive-time-polygon-on-a-google-map-how-far-you-can-go-in-1-hour-or-more-36ph</link>
      <guid>https://dev.to/tomasitraveltime/drawing-a-drive-time-polygon-on-a-google-map-how-far-you-can-go-in-1-hour-or-more-36ph</guid>
      <description>&lt;p&gt;If you've ever wondered 'how far can I drive within 30 minutes?' you're not alone. Hundreds of people each week are looking to discover a way to draw a driving polygon on a Google map. &lt;/p&gt;

&lt;p&gt;Using Google Distance Matrix to make this shape means you'll either need to fire lots of expensive requests to the Google Routing API or you'll end up with a very basic polygon. The tutorial linked below is a walkthrough of how to make this visualization using the TravelTime API. You can sign up for a free trial key from TravelTime without adding your billing details.&lt;/p&gt;

&lt;p&gt;The API works by calculating every possible latitude/longitude coordinate that rests on the travel time parameter. You will only need to make 1 API request to visualize a travel time polygon (aka isochrone).  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S3x5Pkjj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/B6JCj58/15min-Driving.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S3x5Pkjj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.ibb.co/B6JCj58/15min-Driving.png" alt="15 minute driving"&gt;&lt;/a&gt;&lt;/p&gt;
15 minute driving travel time polygon using Google Maps &amp;amp; TravelTime API



&lt;p&gt;The shape above is an example of a 15 minute drive time area in Central London. Travel time polygons can be any size from 5 minutes to 4 hours. It's also possible to use the tutorial to create polygons for walking, cycling, public transport, or combined transport modes.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Use cases
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Draw many polygons for 5, 10, 15, 20, 25, 30 mins to see a heat map of where's reachable in different time catchments.&lt;/li&gt;
&lt;li&gt;Overlap polygons and visualise where's mutually reachable by two or more start locations.&lt;/li&gt;
&lt;li&gt;Combine polygons together. For example draw a 30 minute travel time area around every supermarket in the country. Combining this shapes will polarise the map to see the total accessible zones and total inaccessible zones.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://traveltime.com/blog/google-maps-drive-time-polygon-tutorial-driving-radius"&gt;READ TUTORIAL WALKTHROUGH&lt;/a&gt;
&lt;/h1&gt;

</description>
      <category>tutorial</category>
      <category>webdev</category>
      <category>datascience</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Step by step free geocoding for Leaflet</title>
      <dc:creator>tomastraveltime</dc:creator>
      <pubDate>Wed, 29 May 2019 07:25:36 +0000</pubDate>
      <link>https://dev.to/tomasitraveltime/step-by-step-free-geocoding-for-leaflet-1em5</link>
      <guid>https://dev.to/tomasitraveltime/step-by-step-free-geocoding-for-leaflet-1em5</guid>
      <description>&lt;p&gt;Leaflet is an open source javascript library for interactive maps. While it is designed to be as simple to use as possible, you can extend Leaflet functionality by using external plugins. There are several plugins you can use for geocoding with Leaflet. The example below will show you how to create a simple geocode request for a Leaflet map using the free &lt;a href="https://docs.traveltimeplatform.com/overview/introduction" rel="noopener noreferrer"&gt;TravelTime Search API&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This &lt;a href="https://docs.traveltimeplatform.com/reference/geocoding-search/" rel="noopener noreferrer"&gt;geocoder&lt;/a&gt; allows users to visualise their search results as pins on a map, as well as having a list view of addresses. It is available to be integrated into your app or website.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.traveltimeplatform.com%2Fhs-fs%2Fhubfs%2F1-6.png%3Ft%3D1534774773883%26width%3D1600%26name%3D1-6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.traveltimeplatform.com%2Fhs-fs%2Fhubfs%2F1-6.png%3Ft%3D1534774773883%26width%3D1600%26name%3D1-6.png" alt="image0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To start geocoding for Leaflet using this &lt;a href="https://docs.traveltimeplatform.com/reference/geocoding-search/" rel="noopener noreferrer"&gt;free geocoder&lt;/a&gt;, you’ll first need to request a &lt;a href="https://docs.traveltimeplatform.com/overview/getting-keys/" rel="noopener noreferrer"&gt;TravelTime API key&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simple geocoding request
&lt;/h2&gt;

&lt;p&gt;This example will show you how to geocode a location string to coordinates and show the location on the map.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.traveltimeplatform.com%2Fhs-fs%2Fhubfs%2Fimage2.png%3Fwidth%3D1828%26name%3Dimage2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.traveltimeplatform.com%2Fhs-fs%2Fhubfs%2Fimage2.png%3Fwidth%3D1828%26name%3Dimage2.png" alt="image1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of this will be done in a single HTML document using a Leaflet map library, native JavaScript AJAX calls jQuery for communicating with TravelTime Search API.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 1: Create and import templates
&lt;/h2&gt;

&lt;p&gt;First we need to create a HTML template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Geocoding for Leaflet&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;!DOCTYPE html&amp;gt;
    &amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.3.0/leaflet.css" /&amp;gt;
        &amp;lt;link rel="stylesheet" href="css.css" /&amp;gt;
        &amp;lt;script src="https://unpkg.com/leaflet@1.4.0/dist/leaflet.js" integrity="sha512-QVftwZFqvtRNi0ZyCtsznlKSWOStnDORoefr1enyq5mVL4tmKB3S/EnC3rRJcxCPavG10IcrVGSmPh6Qw5lwrg==" crossorigin=""&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;/head&amp;gt;

    &amp;lt;body&amp;gt;
    &amp;lt;div id="mapid"&amp;gt;&amp;lt;/div&amp;gt;

    &amp;lt;div id="error" class=""&amp;gt;
        &amp;lt;p&amp;gt;&amp;lt;b&amp;gt;No API and APPLICATION_ID key inserted &amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;
        &amp;lt;p&amp;gt;&amp;lt;a target="_blank" href="http://docs.traveltimeplatform.com/overview/getting-keys/"&amp;gt;Sign up for an API key&amp;lt;/a&amp;gt;
            &amp;lt;p&amp;gt;Place it in API and APPLICATION_ID variables&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script&amp;gt;
        // all code will go here
    &amp;lt;/script&amp;gt;
    &amp;lt;style&amp;gt;
        // all style will go here
    &amp;lt;/style&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the header, we import Leaflet’s CSS template and JavaScript library as well as jQuery. The single &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; element will contain the map.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 2: Set location name
&lt;/h2&gt;

&lt;p&gt;To make the example easier, we set the name for the location as a variable inside the code. In real world use that will most likely typed into the search bar by the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP 3: Add headers
&lt;/h2&gt;

&lt;p&gt;The TravelTime API authenticates using headers so we will need to include those too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var locationName = "Tour Eiffel, Paris, France";

var APPLICATION_ID = "place your app id here";
var API_KEY = "place your api key here";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 4: Send request
&lt;/h2&gt;

&lt;p&gt;Now we can send a request to the Geocoding API. It is a very simple GET request that requires only a &lt;code&gt;query&lt;/code&gt; field containing the name of the location. You can view a reference in the &lt;a href="https://docs.traveltimeplatform.com/reference/geocoding-search/" rel="noopener noreferrer"&gt;TravelTime Search API Geocoding documentation&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sendGeocodingRequest(location) {
return fetch(`https://api.traveltimeapp.com/v4/geocoding/search?query=` + location, {
method: "GET",
credentials: "same-origin",
headers: {
"Content-Type": "application/json",
"X-Application-Id": APPLICATION_ID,
"X-Api-Key": API_KEY
}

})
.then(response =&amp;gt; response.json()); // parses JSON response into native Javascript objects
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  STEP 5: Draw markers
&lt;/h2&gt;

&lt;p&gt;In the success parameter, we reference a function that draws a marker on the map using the coordinates returned by the API. Here is the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function drawMarker(response) {  // We need to extract the coordinates from the response.

var coordinates = response.features[0].geometry.coordinates;  // The coordintaes are in a [&amp;lt;lng&amp;gt;, &amp;lt;lat&amp;gt;] format/

var latLng = L.latLng([coordinates[1], coordinates[0]])  // The url template for OpenStreetMap tiles.
var osmUrl = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";     // Creates the tile layer.

var osmTileLayer = L.tileLayer(osmUrl, {
minZoom: 8,
maxZoom: 15
});  // Adds the tile layer to the map.

var map = L.map("mapid").addLayer(osmTileLayer); 
map.setView(latLng, 11);  // Creates a marker for our departure location and adds it to the map.

var markter = L.marker(latLng).addTo(map);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The full code
&lt;/h2&gt;

&lt;p&gt;Finally we just call the `sendGeocodingRequest’ function to run everything. &lt;a href="https://gist.github.com/tomasigeolise/4886bbe53b40758851514c820ae4de26" rel="noopener noreferrer"&gt;The full code can be found here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Live code editor environment
&lt;/h2&gt;

&lt;p&gt;Use CodePen to start testing now. You will need to sign up for a free API key.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/igeolise/embed/JVgjKV?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  About the TravelTime API
&lt;/h2&gt;

&lt;p&gt;The TravelTime API can do many things as well as free geocoding: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Display where's reachable within a time limit on a map, based on the mode of transport&lt;/li&gt;
&lt;li&gt;Calculate a travel time matrix (often called a distance matrix) from an origin to thousands of destinations&lt;/li&gt;
&lt;li&gt;A to B routing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To start using the TravelTime geocoder sign up for an API key. To learn more about geocoding for Leaflet, &lt;a href="https://www.traveltimeplatform.com/contact-us" rel="noopener noreferrer"&gt;get in touch&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
