我正在尝试使用距离矩阵 API 来计算两个地方之间的距离。因为这是我第一次尝试使用这个 API,所以我随便复制了我在Google 文档页面上找到的代码 并粘贴到我的页面上。但是,我看不到任何类型的输出,也不知道为什么。这是我的页面
这是来源:
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<!-- Google Api -->
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDDMkiaVfr1y0QCsx_qUsJKIBAWpkyXZrY&sensor=false">
</script>
<script type="text/javascript">
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,
avoidHighways: false,
avoidTolls: false
}, callback);
function callback(response, status) {
if (status == google.maps.DistanceMatrixStatus.OK)
{
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
document.writeln(response.originAddresses[1]);
}
else {
document.writeln("error");
}
}
</script>
</html>