Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show Traffic layer on top of Directions polyline in google maps API

I am using the Javascript API to show a google map with directions (based on user input) along with the traffic layer. it works well, but i cannot figure out a way to show the traffic colors on the relevant polylines above my custom created line. what's the correct way to do this?

like image 249
kob490 Avatar asked Jul 17 '15 16:07

kob490


1 Answers

Try to use Embed API in directions mode. Details about it you can find it here (Embed API in Direction mode). Here is an example which looks like this.

  <iframe
    width="600"
    height="450"
    frameborder="0" style="border:0"
    src="https://www.google.com/maps/embed/v1/directions?key=YOUR_API_KEY&origin=indira+nagar+Bangalore&destination=Whitefield+Bangalore&avoid=tolls|highways" allowfullscreen>
  </iframe>

Which will give you below output.

enter image description here

You can generate src URL dynamically for run time source - destination traffic route display.

like image 58
Jyotirmay Avatar answered Sep 29 '22 05:09

Jyotirmay