banner



how do i draw a radius on google maps?

Testify driving radius Google Maps

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

The word 'radius' suggests that we volition be showing a round shape on a map, however, this blazon of driving radius may exist only in a perfectly flat earth with no twisty roads or terrain to go around. Only and then could nosotros have a circular 'as the crow flies' travel fourth dimension shape.

We volition be drawing a shape that resembles the real world and it volition show which locations tin be reached from a signal in a given time frame. This shape is called an isochrone and it shows points of an equal value joined together.

How to build if you don't utilise lawmaking

This tutorial is intended for developers interested in implementing a radius travel time on their projects. If you lot're not a programmer but notwithstanding desire to create a travel fourth dimension map, employ our set up to get tool by clicking beneath.

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

Image shows an example using the code-free tool.

Travel time map Google edition

Google does not own an API that can create polygons and then we use TravelTime to prove you how to draw a driving radius on Google Maps. The very first thing we need to get started is a Google Maps API cardinal. If you don't have 1 however, yous will need to go to Google Cloud Platform Panel and fix one up. If you lot are not sure how to get an API key, Google has a guide you can follow. The name of the API that you need is "Maps JavaScript API"

After setting upwards the new API key, make sure you have enabled the key – otherwise your map will not piece of work. If you're facing this problem, at that place's a guide you lot can try on how to enable an API central.

Cost effective Google Maps alternative

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

Setting upward the Google Maps driving distance estimator

In this example, we will be setting upwardly our map to display London Waterloo Railroad train Station and put a marker on it. Then let's brainstorm to create our Google Maps drive fourth dimension polygon.

To take a full sized map on a page, we demand to add some styles to the lawmaking, in this case an .html file.

First, we add a few elements to the trunk:

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

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

Cartoon the driving radius in Google Maps

At present that we have washed the initial setup, let'southward add TravelTime information and draw a Google map isochrone by bulldoze time.

First, you volition demand a TravelTime API cardinal, you can get a central hither, if you don't have one. Once yous setup we should add some more than code to handle the creation of the travel time shape and communication with TravelTime API.

Nosotros need to add a couple of items to the initMap() function. First we need a polygon handling method for getting the premises of the isochrone, this volition let y'all to zoom to the fatigued polygon shape when it'south received afterwards search. Then we demand to add sendGeocodingRequest part which will endeavor TravelTime data and if everything is alright, a polygon will be drawn.

And so in the second script, we demand to take setting variables inserted:

  • startingLocation - a string that will exist geocoded as the starting point;
  • departureTime - this variable adds function to employ the electric current engagement, but information technology can be inverse;
  • travelTime - travel time in seconds;
  • APPLICATION_ID - application won't work without correct authorisation;
  • API_KEY - application won't work without correct authorisation.

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

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

sendTimeMapFunction role will packet upwards parameters into JSON format and ship a Mail service asking to the TravelTime /time-map endpoint. In this function, we use the latitude and longitude that was geocoded in the previous step. The parameters of the driving radius needed are also defined hither, for case, you tin can change the "public_transport" type to "driving" and other transportation types supported by the API.

The concluding part in the script is drawTimeMap, this part handles drawing of the polygons received from TravelTime API. In the polygon variable of this office you tin can make changes to the colours, opacity, border width of the drive time radius shape.

The full instance of the code explained in this blog postal service can be constitute here.

Nosotros take an additional tutorial explaining how to draw a driving radius using Leaflet JavaScript library if you lot wish to use another map provider. TravelTime supports more map tile providers if yous don't desire to employ Google Maps equally in this tutorial.

Visualising 'how far tin can i travel' within a fourth dimension limit

Google Maps travel time radius using public transport 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 altitude radius: 15 minute radius

travel time radius map google

Map data ©2019 Google

Google Maps walking distance radius: 15 minute radius

google maps walking distance radius

Map data ©2019 Google

Travel time radius map Google ideas

Creating a single drive fourth dimension radius on a map is but the beginning of what you tin can do with the TravelTime API time map endpoint. Here are three ideas of what else you tin can exercise with doing slight modifications to the base of operations lawmaking that nosotros already went through:

Create a heat map using various travel times

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

The example compares where's reachable within 10 minutes, 20 minutes, 30 minutes, 40 minutes using public send. The layering of the shapes gives the advent of a travel time estrus map.

travel time map google

Map data ©2019 Google

Create an intersection

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

Case shows an intersection of 2 shapes. 1 shape shows thirty minutes of reachable surface area from London Waterloo Station and the other shape shows xxx minutes of reachable area from Canary Wharf, both using public ship. The regal shows where both shapes overlap.

show driving radius google maps

Map data ©2019 Google

Full code tin can exist institute here.

Create unions of all shapes

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

The New York Times analysed the whole of the USA to see which parts of America have limited access to emergency rooms during the COVID-19 pandemic. The visualisation below was created by sending thousands of requests to TravelTime API and afterward processed to create a big scale map. The orange pinpoints all locations more than than 30 minutes abroad from an emergency room.

driving-radius

Reference: The New York Times

Become your TravelTime API primal and start creating your ain driving radius map.

Get AN API KEY

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

Posted by: hammittlever2000.blogspot.com

0 Response to "how do i draw a radius on google maps?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel