Access to fare properties in Google javascript API pointers

How do I access the fare property for transit destinations in the google JavaScript API? The following line does not work:

alert(response.routes[j].legs[k].fare.value); 

The API page says:

the fare contains the total fare (i.e. the total cost of tickets) for this route. This property is returned only for transit requests and only for routes where tariff information is available for all transit legs. Information includes:

  • currency: ISO 4217 currency code indicating the currency in which the amount is expressed.
  • value: the total fare in the currency indicated above.

thanks

+6
source share
1 answer

Tariff information will not be included in the “Destinations” response if your request is not identified with your API key [1]. This applies to both the Directions API web service and the Directions service in the JavaScript API for Maps.

Here is an example of a web service, you will see tariff information (right after the "copyright"), as soon as you add your own API (server):

https://maps.googleapis.com/maps/api/directions/json?origin=NE+Fremont+and+80th+Portland+OR&destination=Portland+OR&mode=transit&departure_time=1466096686

Here is an example JavaScript API: http://jsbin.com/rumugu/edit?html,output

  • if you place your (API) API, you will see a $ 2.50 popup

  • if you completely remove the key = parameter, undefined will appear "

[1] Clients of Maps API for Work and Premium Plan can also use their client identifier.

+1
source

All Articles