Google Maps widget with traffic

Ah ok, yes thats correct. The browser retrieves that, so when browser sleeps no requests are made.

However I’m still has this ‘false’ labels on the map. Maybe it somehow connected to regional things or I don’t know, maybe someone could help me with this?
Screenshot%20(51)

Go to google console and navigate to the libraryu and activate the Distance Matrix API, this will give permission to do distance calculations.

Hi,

tried to use this nice function.

Startet with the items part and get lots of errors in my OpenHAB Log.

018-11-18 14:13:03.833 [ERROR] [b.core.service.AbstractActiveService] - Error while executing background thread HTTP Refresh Service
java.util.UnknownFormatConversionException: Conversion = ‘F’
at java.util.Formatter$FormatSpecifier.conversion(Formatter.java:2691) [?:?]
at java.util.Formatter$FormatSpecifier.(Formatter.java:2720) [?:?]
at java.util.Formatter.parse(Formatter.java:2560) [?:?]
at java.util.Formatter.format(Formatter.java:2501) [?:?]
at java.util.Formatter.format(Formatter.java:2455) [?:?]
at java.lang.String.format(String.java:2940) [?:?]
at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:144) [244:org.openhab.binding.http:1.11.0]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:144) [200:org.openhab.core.compat1x:2.2.0]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:166) [200:org.openhab.core.compat1x:2.2.0]

The URL itself works fine within the browser.

Any ideas?

Thanks in advance.

Rgds
André

Hi All,
I am very very new to all fo this.
I do not understand where I should be putting the map.html file. I am getting a HHTP error 404
Problem accessing …
Can anyone help me.
Thanks

Win or Linux?

Both, I am experimenting on both but my final system will run on linux.
I know this is a stupid question but where is the /conf/html/google-maps/ folder.

On Windows: inside C:\openHAB2\conf\html you need to create the google-maps/ folder.
On Linux: inside /etc/openhab2/html/ (same story… create the subdir)

Ok Thanks I will try…

Hi
Ok I have google coming up in the widget and can click on it and a new page for google maps comes up.
I see only a small square as well. What should the zoom level and height be set at? could this be the problem?

11

Hi guys,

I got it working but it didn’t show full screen. The calculation was down the bottom which is supposed to be at top left corner.I played around the setting but none helped.Any ideas? Thanks.

Regards
Clement

1st, Thank Bastiaan for the great post. I learned a lot from this post.
Using Bastiaan’s method only show the shortest route and calculate the travel time on this route but this normally includes a lot of small roads and not always the fastest route. So I decided to find the way suits my needs.
The reasons are as below.
1:Many people are like me who needs a travel time for a specific route. If this route is congested, then consider other choices. Google map sometimes also gave wrong fastest route which confused me. And I have to use get direction some times to get the right way.
2:Using latitude and longitude is much better because some suburbs are quite big. The difference traveling to different part of the suburb sometimes is more than 10 mins.This is
the case where I am working.
The change to the map.html is not too much but I tried very hard to find the right codes. I don’t use the widget form to give variables though.

function calculateAndDisplayRoute() {
			var directionsDisplay = new google.maps.DirectionsRenderer;
			var directionsService = new google.maps.DirectionsService;
			directionsDisplay.setMap(map);

			directionsService.route({
				origin : "latitude,longitude",
				destination : "latitude,longitude",
				travelMode: 'DRIVING',
				unitSystem: google.maps.UnitSystem.METRIC,
				waypoints: [
                {
                 location: new google.maps.LatLng(latitude,longitude),
                 stopover: false,
                }],
			  	drivingOptions: {
					departureTime: new Date(Date.now()),
					trafficModel: 'bestguess'
				}
			}, 

The origin,destination and waypoint use latitude and longitude. You need to try different waypoint so the map can show correct route. It is weird that using some waypoints leading to loops on maps so you may need to try many times to find the right waypoints. If your route is complicated then you might need to use a few waypoints which is harder and out of my knowledge.

Regards
Clement

Hello, i need help pls.
I need run this widget on PC in (chrome) but when i opened file map.html i see only this…:

Pls help.

Looks like you are opening the widget directly from a drive, you should use and add the widget in HABPanel.

Yes, i am opening the widget from a drive. Because this perfect widget i need run on the digital-signage displays.

Is it way to run this widget locally from a drive…?

Thank you so much.

No that wont work, it depends on the architecture of Openhab and Angular.

OK :confused:

Thank you.

Hello everyone,

Thanks for the effords to develop this widged. I like it very much.
I have one problem i cant overcome

After a while there are shown multiple paths on the map, like if the old ones weren’t removed. After a manual refresh of the habpanel it shows clean results.
Has anyone encountered the same problem or has is solved?

Thanks in advance

EDIT:
Found a possible hint to the answer here: https://stackoverflow.com/questions/7886110/removing-routes-rendered-on-a-google-map. I’m investigating that.

Greetings

This is brilliant. Thanks Bastiaan.

I had to create a GCP account and linking a CC to it.
At the moment I’ve got it running without any restrictions on the API Key.
Has anyone managed to restrict their API Key successfully?

Anil

I found the solution to my problem:

Declare
var directionsDisplay;
var directionsService;
globaly in line 77 of map.html

Replace line 176&177 with (remove local declaration)
directionsDisplay = new google.maps.DirectionsRenderer;
directionsService = new google.maps.DirectionsService;

and add after line 211 in the if-block:
directionsDisplay.set(‘directions’, null);

My best guess is that every time the directonsDisplay is replaced when updated, that the layer persists, somehow a handler is still remaining. With “directionsDisplay.set(‘directions’, null);” on a globaly declared variable the old directions-layer is removed and can be replaced by the new one.
There is then a recognizeable redrawing of the route.

Another thing that I found anoying is the “window.alert('Directions request failed due to ’ + status);” that shows a popup-message. I replaced that with a status in the panel; saying “OK” or “FAILED”

I hope that helps anyone.