Back

Creating Realtime Traffic Layer

In order to create a realtime traffic layer, call the ShowTrafficLayer method of the map object like this:

 map.ShowTrafficLayer()

And yess, you got it. A realtime traffic is plotted on the map. Just like that.


Traffic Layer Example

app.LoadPlugin("MapView");

function OnStart() {
    lay = app.CreateLayout("Linear", "VCenter, FillXY");
        
        var apiKey = "AIzaSyD2eHntKEmh272p3ac6YjWPbPkwo3m2mck";
        
        map = app.CreateMapView(apiKey, 0.9, 0.5, 7.0689323, 125.6114588, 13);
        map.SetOnReady(MapOnReady);
        lay.AddChild(map);

        btnShow = app.CreateButton("Show Traffic");
        btnShow.SetOnTouch(BtnOnTouch);
        btnShow.Hide();
        lay.AddChild(btnShow);

        btnHide = app.CreateButton("Hide Traffic");
        btnHide.SetOnTouch(BtnOnTouch);
        btnHide.Hide();
        lay.AddChild(btnHide);
    app.AddLayout(lay);
}
function MapOnReady() {
    btnShow.Show();
    btnHide.Show();
}
function BtnOnTouch() {
    if(this.GetText() == "Show Traffic") {
        map.ShowTrafficLayer();
    } else {
        map.HideTrafficLayer();
    }
}
Copy    Run   

ShowTrafficLayer()
This will initialize an instance of the TrafficLayer class and show the layer into the map.

HideTrafficLayer()
This will hide the TrafficLayer object in the map. This will not destroy object. Call the ShowTrafficLayer() method to show it again.

RemoveTrafficLayer()
This will completely destroy TrafficLayer object.