Create routes to a single point google maps API

Asked

Viewed 359 times

0

I have a problem, the problem is the following, I made a request via HTTP I took the data from JSON and I loaded inside one so I was able to load all the points of JSON 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 didn’t 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 request and everything, Anyway, it’s basically this, in case you don’t understand, just ask! Obg!

  • Already solved the problem? How are you creating the route? From what I saw in the code is just putting the markers on the map

  • I already solved yes, I pulled the Merker as parameter for a Function and soon after implemented the route, so it only takes the value of the clicked Marker.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.