Draw Circles on Google Maps of Specific Distance

Show driving radius Google Maps

In this tutorial, nosotros're going to show you how to describe a driving radius on an embedded Google Map on a website. To achieve this we will use data from Google Maps and the TravelTime APIs.

The word 'radius' suggests that we will exist showing a round shape on a map, however, this type of driving radius may exist but in a perfectly flat world with no twisty roads or terrain to go effectually. Only and so could nosotros take a circular 'as the crow flies' travel time shape.

We will be drawing a shape that resembles the real world and information technology will evidence which locations can exist reached from a indicate in a given time frame. This shape is chosen an isochrone and it shows points of an equal value joined together.

How to build if yous don't use code

This tutorial is intended for developers interested in implementing a radius travel time on their projects. If you lot're not a developer but even so want to create a travel time map, use our fix to go tool past clicking beneath.

This tool is a demonstration of the basic capabilities of TravelTime API; in a few clicks you tin create a travel time map using five dissimilar transportation modes.

Image shows an example using the code-free tool.

Travel time map Google edition

Google does not ain an API that can create polygons so we use TravelTime to show you how to draw a driving radius on Google Maps. The very start thing we need to get started is a Google Maps API key. If you don't have one yet, you lot will demand to go to Google Deject Platform Panel and set up one upwards. If you are not certain how to become an API cardinal, Google has a guide you lot tin can follow. The name of the API that y'all need is "Maps JavaScript API"

Afterwards setting upwards the new API fundamental, make sure you have enabled the key – otherwise your map will non piece of work. If you're facing this problem, in that location's a guide you can try on how to enable an API key.

Cost effective Google Maps alternative

TravelTime offers map tiles completely free when using other paid services. Reduce your map services costs. Explore TravelTime tiles.

Setting up the Google Maps driving distance figurer

In this example, we will exist setting upwardly our map to display London Waterloo Train Station and put a marker on it. And so allow'due south brainstorm to create our Google Maps drive fourth dimension polygon.

To have a full sized map on a page, nosotros need to add some styles to the code, in this example an .html file.

First, we add a few elements to the body:

  • a div tag with id of 'map';
  • a script for Google Maps API, this is where you lot'll insert your API key;
  • a script to handle initMap() office which volition exist used to initialise the map on the screen. In the mapOpts variable we set up the heart position of the map, the zoom level that will exist shown by default.

With these elements added, we volition create our map and have a marker positioned at our specified coordinates.

Drawing the driving radius in Google Maps

Now that we have washed the initial setup, let'due south add TravelTime data and draw a Google map isochrone past drive time.

Offset, you volition need a TravelTime API primal, yous can get a cardinal hither, if you don't have one. In one case y'all setup we should add some more code to handle the creation of the travel time shape and advice with TravelTime API.

Nosotros demand to add a couple of items to the initMap() role. Get-go we need a polygon handling method for getting the bounds of the isochrone, this volition permit you to zoom to the drawn polygon shape when information technology's received after search. Then we need to add sendGeocodingRequest office which will endeavour TravelTime information and if everything is alright, a polygon volition exist drawn.

Then in the second script, nosotros need to accept setting variables inserted:

  • startingLocation - a string that will be geocoded as the starting point;
  • departureTime - this variable adds function to utilize the current date, but it tin can exist changed;
  • travelTime - travel time in seconds;
  • APPLICATION_ID - awarding won't work without correct authorisation;
  • API_KEY - application won't work without right authorisation.

After we have the variables divers, we add functions for communicating with the TravelTime API and managing the polygon data that we will receive.

sendGeocodingRequest role will send a query to the free TravelTime Geocoder, this will become coordinates of the location written in the 'location' variable. If the function does its job, it volition call the sendTimeMapRequest function.

sendTimeMapFunction function volition packet up parameters into JSON format and send a POST request to the TravelTime /fourth dimension-map endpoint. In this function, we use the latitude and longitude that was geocoded in the previous pace. The parameters of the driving radius needed are as well divers here, for example, yous can modify the "public_transport" blazon to "driving" and other transportation types supported past the API.

The last function in the script is drawTimeMap, this function handles drawing of the polygons received from TravelTime API. In the polygon variable of this part you tin make changes to the colours, opacity, border width of the bulldoze fourth dimension radius shape.

The full example of the lawmaking explained in this weblog post can exist found here.

We have an additional tutorial explaining how to depict a driving radius using Leaflet JavaScript library if you lot wish to employ another map provider. TravelTime supports more map tile providers if you don't want to apply Google Maps as in this tutorial.

Visualising 'how far tin i travel' inside a time limit

Google Maps travel time radius using public send data: 15 minute radius

google map isochrone

Map data ©2019 Google

Google Maps travel radius using drive times: 15 minute radius

google maps drive time polygon

Map data ©2019 Google

Google Maps cycling distance radius: xv minute radius

travel time radius map google

Map information ©2019 Google

Google Maps walking distance radius: 15 infinitesimal radius

google maps walking distance radius

Map data ©2019 Google

Travel time radius map Google ideas

Creating a unmarried bulldoze fourth dimension radius on a map is only the starting time of what you tin can exercise with the TravelTime API time map endpoint. Here are 3 ideas of what else y'all tin can do with doing slight modifications to the base of operations code that we already went through:

Create a heat map using various travel times

Just by sending boosted requests to the API from the same starting point you can create visualisations representing incremental increases in your travel fourth dimension radius. Full code example for creating this visualisation is bachelor here.

The example compares where's reachable inside 10 minutes, twenty minutes, 30 minutes, xl minutes using public transport. The layering of the shapes gives the advent of a travel time estrus map.

travel time map google

Map information ©2019 Google

Create an intersection

You may want to find common areas betwixt a few drive time radiuses. Overlap multiple polygons and highlight the overlapping area on a Google map.

Example shows an intersection of ii shapes. One shape shows thirty minutes of reachable expanse from London Waterloo Station and the other shape shows 30 minutes of reachable area from Canary Wharf, both using public send. The majestic shows where both shapes overlap.

show driving radius google maps

Map data ©2019 Google

Full code can be found here.

Create unions of all shapes

If you want to make a big visualisation or analyse a hypothesis over large areas, y'all may be interested in making unions of many travel time shapes. Later receiving large amounts of polygon data you can process it to make one big shape, group them together in a variety of ways.

The New York Times analysed the whole of the USA to meet which parts of America have limited access to emergency rooms during the COVID-nineteen pandemic. The visualisation below was created by sending thousands of requests to TravelTime API and afterwards processed to create a large calibration map. The orangish pinpoints all locations more than thirty minutes away from an emergency room.

driving-radius

Reference: The New York Times

Get your TravelTime API key and start creating your own driving radius map.

GET AN API Central

powellthosped.blogspot.com

Source: https://traveltime.com/blog/google-maps-drive-time-polygon-tutorial-driving-radius

0 Response to "Draw Circles on Google Maps of Specific Distance"

Postar um comentário

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel