Friday 15 April 2011

javascript - Using a Google Apps API key with Distance Matrix -



javascript - Using a Google Apps API key with Distance Matrix -

i using google distance matrix api , documentation tells me need api key (but can utilize without one.) i'd able monitor utilize i'm stumped how set up.

i have valid browser application api key google developers console, it's new i'm assuming it's version 3 key.

i have added valid referers in console

i have <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> on page

i'm using code this

function callback(response, status) { if (status!==google.maps.distancematrixstatus.ok) { _googleerror('error was: ' + status); } else { var origins = response.originaddresses; (var = 0; < origins.length; i++) { var results = response.rows[i].elements; (var j = 0; j < results.length; j++) { $("#calcdistance").val(results[j].distance.text); //other stuff works here } } } } function calculatedistances(start, end) { var service = new google.maps.distancematrixservice(); service.getdistancematrix( { origins: [start], destinations: [end], travelmode: google.maps.travelmode.driving, unitsystem: google.maps.unitsystem.imperial, avoidhighways: false, avoidtolls: false }, callback); }

as things work fine. when seek add together key in things go south. i've tried

<script src="https://maps.googleapis.com/maps/api/js?key={my_key}&v=3.exp"></script>

and

<script src="https://maps.googleapis.com/maps/api/js?key={my_key}"></script>

with no luck. when either of error invalid url, similar question.

i've tried adding key: {my_key}, calculatedistances() - no luck either.

am missing obvious? (i sense am)

update:

@dr.molle's reply got me looking for. turned on "google maps javascript api v3" , changed <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script> <script src="https://maps.googleapis.com/maps/api/js?key={my_key}&v=3.exp"></script> can view activity in developer console wanted.

when utilize key when loading maps-javascript-api must enable api "google maps javascript api v3" within console.

the linked documentation webservice, key-related part of documentation irrelevant when request distancematrixservice via javascript-api.

the right documentation you'll find @ https://developers.google.com/maps/documentation/javascript/distancematrix

javascript api google-maps google-maps-api-3

No comments:

Post a Comment