Google Maps widget with traffic

Tags: #<Tag:0x00007fe05325dd08> #<Tag:0x00007fe05325dba0>

(Bastiaan van Haastrecht) #21

Go to the OH manual:

Choose your OS and look for the ‘Site configuration’ folder. Find this folder on your OH box. Within this folder there should be a ‘html’ directory, within that directory create a sub directory ‘google-maps’ and place the ‘maps.html’ here.

Then your path in the settings of the widget should be ‘/static/google-maps/map.html’ .

(Bastiaan van Haastrecht) #22


So you would like multiple calculations. Would you want all routes to be printed on the widget? That could get confusing. I’m thinking about creating a seperate widget just for travel time calculations, no map.

(sceppi) #23

No no, that’s not the issue. I’m well aware where the html folder is on my PI and the files have been correctly placed there.

I meanwhile found the issue and have been able to fix it. Don’t ask me why or how, but it was related to the HabPanel storage configuration. I use the configuration which is saved on the server (so no local storage).

  • I first tried the widget on a different client with the server configuration. That didn’t work.
  • I then switched to local storage (which was empty as it was a different client), and then it the widget worked!
  • I then used my own pc again on server configuration, which again didn’t work
  • I then switched my own pc to local configuration, which was not empty yet. I deleted the local storage configuration and cleared the cache from my browser. Then tried the widget again from the local configuration and it worked
  • Then finally switched again to server configuration and now it worked

–> So basically, as far as I could tell, there was an existing local configuration on my PC which seemed to cause a conflict.

@danielwalters86 : You should try this yourself: go to local configuration, clear it completely (including wiping all the cache), and then switch to server configuration again.

(Massimo) #24

I m also interested in getting travel time calculations with/without traffic + best route suggested inside OpenHAB.
But that looks more like a good candidate for a new binding than just a HABpanle widget.
This way travel times can be used in rules and trigger other items.
What do think?

(Bastiaan van Haastrecht) #25

@massi, no need for a binding, you can get the travel time in an item with calling the Google Maps API thru an URL and parse the result with JSONPath.

(Christoph) #26

You could do the same also with bing maps.

(Mr. Yoinkz) #27

I think that would make sense. It could end up being a bit confusing.

I somewhere saw something like this:

Unfortunately I can’t find the correct one, but it is like the above picture where it just said

Him Her
traveltime traveltime

And then the knob wheel thing so it shows some graphical things so it’s not all text :).

Does it make sense?

Then you could have the nice map beneath so it shows the overall status of the roads :smiley: nice nice nice!

(Bastiaan van Haastrecht) #28

You can do it like this.

Create a ‘googlemaps.items’ file in ‘/conf/items’. Change the value’s in the URL to your liking.

String	GoogleMaps_me_distance				"Distance [%s]"		(gGoogleMaps)	{ http="<[$.rows[0].elements[0].distance.text)]" }
String	GoogleMaps_me_duration				"Duration [%s]"		(gGoogleMaps)	{ http="<[$.rows[0].elements[0].duration.text)]" }
String	GoogleMaps_me_duration_traffic		"Duration [%s]"		(gGoogleMaps)	{ http="<[$.rows[0].elements[0].duration_in_traffic.text)]" }

String	GoogleMaps_wife_distance			"Distance [%s]"		(gGoogleMaps)	{ http="<[$.rows[0].elements[0].distance.text)]" }
String	GoogleMaps_wife_duration			"Duration [%s]"		(gGoogleMaps)	{ http="<[$.rows[0].elements[0].duration.text)]" }
String	GoogleMaps_wife_duration_traffic	"Duration [%s]"		(gGoogleMaps)	{ http="<[$.rows[0].elements[0].duration_in_traffic.text)]" }

More Google Maps API options here.

Add a Dummy widget for every String. You can set it up like this:

I’m not going to build a custom widget as it’s just plain simple displaying strings.

(Mr. Yoinkz) #29

I think this is good :slight_smile:
It should also work with a knob is desired

Funny that it is faster for you when traffic is present :stuck_out_tongue:

(Bastiaan van Haastrecht) #30

Yup, Duration is the average traffic, so could be that current traffic confditions are better then normal, it’s holiday season over here. :slight_smile:

(Mr. Yoinkz) #31

Sounds lovely :slight_smile:

How often does this one update? Also every 10 second?

(Bastiaan van Haastrecht) #32

Nope, 60 seconds, but you can adjust by this parameter in the URL string:


Its in milliseconds.

(Mr. Yoinkz) #33

Argh, it doesn’t work out for me :(.
I can’t get it showing any calculations or distance… hmmm…

(James Hiscott) #34

Fixed my problems, silly mistake.

You need the HTTP binding installed. Whops!

(Bastiaan van Haastrecht) #35

Yup you need the HTTP binding. Will update the instructions.

Just a note, origin or destination contains spaces, replace them with ‘+’ plus sign.

(Mr. Yoinkz) #36

Yes the HTTP binding also did the trick for me! Looks wonderful.

Now I will try to see if I can get the a knob working with the input! NICE WORK!

(Daniel Walters) #37

Appreciate that your post was to illustrate a point but I wouldn’t advocate calling the Google Maps API three times like that - it’s unnecessary and continued use like that may eat your usage allowance. I would instead only call it once and then use a rule to extract the relevant bits using JSONPath and call postUpdate.

(Lucky) #38

I don’t think he’s gonna hit the 2500 request limit per 24 hours

(Mr. Yoinkz) #39

Well I think I did ?


Is there anything I can do to avoid this?

(Daniel Walters) #40

3 requests per minute equals 4320 requests a day.

Looks like @Yoinkz may have proven my point.

@Yoinkz how often are you sending your requests? Also how many?