<script type=text/javascript src=https://maps.googleapis.com/maps/api/js? sensor=false></script>
<script language=JavaScript>
var mileageidx = new Number();
function getMileage(idx)
{
// code snipped
mileageidx = idx;
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix({ origins: [zipCode], destinations: [hostClubZipCode], travelMode: google.maps.TravelMode.DRIVING, unitSystem: google.maps.UnitSystem.IMPERIAL, avoidHighways: false, avoidTolls: false}, callback());
// code snipped
}
function callback(response, status)
{
alert('in callback routine, mileageidx ='+mileageidx+' google status = '+status);
if (status == google.maps.DistanceMatrixStatus.OK)
{
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
for (var i = 0; i < origins.length; i++)
{
var results = response.rows[i].elements;\n";
for (var j = 0; j < results.length; j++)\n";
{
var element = results[j];
var distance = element.distance.text;
alert('distance='+distance);
var duration = element.duration.text;
var from = origins[i];
var to = destinations[j];
}
}
}
else
{
if (status == google.maps.DistanceMatrixStatus.INVALID_REQUEST)
{
alert('google.maps.DistanceMatrixStatus was INVALID_REQUEST');
}
if (status == google.maps.DistanceMatrixStatus.MAX_ELEMENTS_EXCEEDED)
{
alert('google.maps.DistanceMatrixStatus was MAX_ELEMENTS_EXCEEDED');
}
if (status == google.maps.DistanceMatrixStatus.OVER_QUERY_LIMIT)
{
alert('google.maps.DistanceMatrixStatus was OVER_QUERY_LIMIT ');
}
if (status == google.maps.DistanceMatrixStatus.REQUEST_DENIED)
{
alert('google.maps.DistanceMatrixStatus was REQUEST_DENIED');
}
if (status == google.maps.DistanceMatrixStatus.UNKNOWN_ERROR)
{
alert('google.maps.DistanceMatrixStatus was UNKNOWN_ERROR');
}
}
}
执行代码时,我收到消息“b”为空或不是对象 DistanceMatrixService.getDistanceMatrix 第 1 行代码:0 字符:1 URL:https://maps.googleapis.com/maps/api/js/DistanceMatrixService。 GetDistanceMatrix?1m1&2s80 ...
此代码工作了两次,然后开始出现此错误。