Create routes for a single API google Maps API

0

I have a problem, the problem is the following, I made a request via HTTP I got the JSON data and loaded it inside a for so I was able to load all JSON points into the map:

var get = function(url, callback) {
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4) {
                callback(xhr.responseText, xhr.status);
            }
        };
        xhr.open('GET', url);
        xhr.send(null);
    };


    get("http://site/", function(data, status){
        var dH = JSON.parse(data);
    });
    for(var i = 0; i < dH.length; i++) {
        var dHs = dH[i];
        var marker = new google.maps.Marker({
                position: {lat: parseFloat(dHs.latitude), lng: parseFloat(dHs.longitude)},
                map: map,
                icon: "img/"+dHs.icon,
                title: dHs.nome_hs,
            });
    }

I tried inside to create a route, but obviously it did not work because the route was created for the last location loaded inside the for, now I need to find a way to create a route to a specific location that is inside the JSON file where I made the requisition and everything, anyway, it's basically that, in case you do not understand, just ask! Obg!

    
asked by anonymous 06.03.2016 / 17:13

0 answers