Google的Distance Matrix Service确实很有帮助,但我想将结果导出为CSV。有人可以帮助我吗?
以下是Google Distance Matrix API的参考: https://developers.google.com/maps/documentation/javascript/examples/distance-matrix
在这种情况下,我想将outputDiv.innerHTML
导出到CSV文件。这是我的代码:
<script>
function initMap() {
var service = new google.maps.DistanceMatrixService;
service.getDistanceMatrix({
origins: [<?php print_r ($resultAM); ?>], //my cooridnates
destinations: [<?php print_r ($resultAM); ?>], //my cooridnates
travelMode: 'DRIVING',
unitSystem: google.maps.UnitSystem.METRIC,
avoidHighways: false,
avoidTolls: false
},
function(response, status) {
var originList = response.originAddresses;
var destinationList = response.destinationAddresses;
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = '';
for (var i = 0; i < originList.length; i++) {
var results = response.rows[i].elements;
for (var j = 0; j < results.length; j++) {
outputDiv.innerHTML += results[j].distance.text + ',';
}
}
});
}
</script>