Page 1 of 1

google maps traffic

Posted: Wed Sep 05, 2018 8:51 pm
by Jodye
Is there any way to put google maps traffic in? Its on the google maps website but not listed in the maps menu in VRS. In addition to VRS, I also use a scanner and was hoping to get planes and automobile traffic on the same page. Im afraid i am not good with coding at all, so I cant write my own plugin.

Re: google maps traffic

Posted: Wed Sep 05, 2018 11:05 pm
by kiwikieran
According to the API:
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}

I will see if I can make a plugin

Re: google maps traffic

Posted: Thu Sep 06, 2018 5:29 am
by Jodye
Thank you, I would really appreciate it.

I did run across that code snip-it, although it was larger. I did get a developer api key and put it in, corrected the lat and long, placed it in an empty html file and inserted it. Everytime I use the key it gives me an error. Tried your small code and the page builds, but the option doesnt show up.

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Traffic Layer</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 13,
center: {lat: 34.04924594193164, lng: -118.24104309082031}
});

var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js ... ck=initMap">
</script>
</body>
</html>

Re: google maps traffic

Posted: Mon Sep 17, 2018 11:35 pm
by agw
That's an example web page showing the markup and the script to create a map with the traffic layer turned on. It won't work with VRS.

This should work but I've not been able to test it because of the recent(ish) changes to Google's billing requirements. But it should work:

Code: Select all

<script type="text/javascript">
    if(VRS && VRS.globalDispatch && VRS.serverConfig) {
        VRS.globalDispatch.hook(VRS.globalEvent.bootstrapCreated, function(bootStrap) {
            if(bootStrap.hookMapInitialised) {
                bootStrap.hookMapInitialised(function(pageSettings) {
                    // Only run this if VRS is using Google Maps
                    if(pageSettings.mapPlugin && pageSettings.mapPlugin.getNativeType() === 'GoogleMaps') {
                        // Get the Google Maps map handle
                        var map = pageSettings.mapPlugin.getNative();

                        // Add the traffic layer
                        var trafficLayer = new google.maps.TrafficLayer();
                        trafficLayer.setMap(map);
                    }
                });
            }
        });
    }
</script>

Re: google maps traffic

Posted: Thu Sep 20, 2018 3:41 am
by Jodye
Works perfect. Thank you!!!!!