google maps traffic

The "to-do" list for Virtual Radar Server is as long as my arm, but if you want to pile more work onto it then this is for you.
Post Reply
Jodye
Posts: 3
Joined: Wed Sep 05, 2018 8:39 pm

google maps traffic

Post by Jodye » Wed Sep 05, 2018 8:51 pm

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.

kiwikieran
Posts: 59
Joined: Sat Jan 20, 2018 8:50 pm

Re: google maps traffic

Post by kiwikieran » Wed Sep 05, 2018 11:05 pm

According to the API:
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
}

I will see if I can make a plugin

Jodye
Posts: 3
Joined: Wed Sep 05, 2018 8:39 pm

Re: google maps traffic

Post by Jodye » Thu Sep 06, 2018 5:29 am

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>

agw
Posts: 2130
Joined: Fri Feb 17, 2012 3:20 am

Re: google maps traffic

Post by agw » Mon Sep 17, 2018 11:35 pm

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>

Jodye
Posts: 3
Joined: Wed Sep 05, 2018 8:39 pm

Re: google maps traffic

Post by Jodye » Thu Sep 20, 2018 3:41 am

Works perfect. Thank you!!!!!

Post Reply