コードに距離と期間が表示されないのはなぜですか?
これは私のコード(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出力の例です。