为什么我的代码不显示距离和持续时间?
这是我的代码(html + js):
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta charset="utf-8" />
<title>Google</title>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
#result{
width: 300px;
height: 400px;
background-color: red;
}
</style>
<script>
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: ["Berlin"],
destinations: ["Frankfurt"],
travelMode: google.maps.TravelMode.DRIVING,
}, callback);
function callback(response, status) {
$("#result").text(response.rows[0].elements.distance.text + " and " + response.rows[0].elements.duration.text);
}
</script>
</head>
<body>
<div id="result"></div>
</body>
</html>
这是示例 JSON 输出: