I am trying to use google.maps.DistanceMatrixService()
with some other services (google.maps.LatLng
, google.maps.DirectionsService
) and I get this error
js?key=MYKEY:35 InvalidValueError: in property origins: not an Array
Stack trace ends at distance_matrix.js:1 if that helps.
Code works without problems until I add part with distance matrix. My intuition was that it wants multiple keys for multiple APIs in form of array, but I am probably wrong (sorry I am a beginner in javascript). I tried to do some research but I was unable to find anything about this error. I tried creating key for distances matrix, using multiple keys, I also used string values for origins/destination to make sure the error is not here. But nothing worked.
This is my code:
var distanceService = new google.maps.DistanceMatrixService();
distanceService.getDistanceMatrix({
origins: jams[i].getCenter(),
destinations: coordinates,
unitSystem: google.maps.UnitSystem.METRIC,
durationInTraffic: true
},
function (response, status) {
if (status !== google.maps.DistanceMatrixStatus.OK) {
console.log('Error:', status);
} else {
console.log(response);
$("#distance").text(response.rows[0].elements[0].distance.text).show();
$("#duration").text(response.rows[0].elements[0].duration.text).show();
}
});
Here is also the code for loading libraries and API key (this part was not written by me):
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MYKEY"></script>
<script src="https://cdn.rawgit.com/googlemaps/v3-utility-library/infobox/1.1.13/src/infobox.js
"></script>
via Kanter
No comments:
Post a Comment