julienhaversano
julienhaversano

Reputation: 446

Gmaps.js route with time

I'm trying to output the route time from the location, for some reason the route never goes through.

jQuery(document).ready(function () {
    $.get('api/index.php', function(data) {
        data = JSON.parse(data);
        var map = new GMaps({
            div: '#map',
            lat: 40.715520,
            lng: -74.003409
            zoom: 10
        });
        map.getRoutes({
            origin: [40.715520, -74.003409],
            destination: [data.lat, data.lon],
            callback: function(e) {     
                var time = 0;
                for (var i = 0; i < e[0].legs.length; i++) {
                    time += e[0].legs[i].duration.value;            
                }
                $('.time').html(time);
            } 
        });
    });
});

Am I do anything wrong? I have tried this before and it worked fine.

Here is the api output: {"lat":40.9238473,"lng":-73.237647}

Upvotes: 0

Views: 582

Answers (1)

David
David

Reputation: 325

Missing a comma between lng and zoom property when you create the map:

var map = new GMaps({
    div: '#map',
    lat: 40.715520,
    lng: -74.003409,
    zoom: 10
});

And you need to use the property data.lng insted of data.lon when you call the map.getRoutes method:

map.getRoutes({
            origin: [40.715520, -74.003409],
            destination: [data.lat, data.lng],
            ... 
        });

Upvotes: 1

Related Questions