javascript - Google Maps v3 Distance Matrix to find closest location -
i creating windows store application in javascript.
i have list of locations in json object array(destinations) , array of json objects(origins).
i click on origin marker , use distance matrix find closest destination or list of sorted destinations.
i don't want use php or that.
please me!
thank you
the documentation pretty neat;
var origin1 = new google.maps.latlng(55.930385, -3.118425); var origin2 = "greenwich, england"; var destinationa = "stockholm, sweden"; var destinationb = new google.maps.latlng(50.087692, 14.421150); var service = new google.maps.distancematrixservice(); service.getdistancematrix( { origins: [origin1, origin2], destinations: [destinationa, destinationb], travelmode: google.maps.travelmode.driving, unitsystem: unitsystem, durationintraffic: boolean, avoidhighways: false, avoidtolls: false }, callback); function callback(response, status) { if (status == google.maps.distancematrixstatus.ok) { var origins = response.originaddresses; var destinations = response.destinationaddresses; (var = 0; < origins.length; i++) { var results = response.rows[i].elements; (var j = 0; j < results.length; j++) { var element = results[j]; var distance = element.distance.text; var duration = element.duration.text; var = origins[i]; var = destinations[j]; } } } }
Comments
Post a Comment