简体   繁体   English

通过Google方向访问jare API中的票价属性

[英]Accessing fare property in Google directions javascript API

How do I access the fare property for transit directions in the google directions javascript API? 如何在Google google javascript API中访问公交路线的票价属性? The following line isn't working: 以下行无效:

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

on the directions API page it says: 在方向API页面上,它说:

fare contains the total fare (that is, the total ticket costs) on this route. 票价包含此路线上的总票价(即票务总票价)。 This property is only returned for transit requests and only for routes where fare information is available for all transit legs. 此属性仅针对运输请求返回,仅适用于所有运输路段均可获得票价信息的路线。 The information includes: 信息包括:

  • currency: An ISO 4217 currency code indicating the currency that the amount is expressed in. currency:ISO 4217货币代码,表示金额表示的货币。
  • value: The total fare amount, in the currency specified above. value:总票价金额,以上面指定的货币计算。

Thank you 谢谢

Fare info will not be included in the Directions response if your request is not identified with your API key[1]. 如果您的请求未通过API密钥[1]标识,则路线响应中不会包含票价信息。 This applies to both the Directions API web service and the Directions service in the Maps JavaScript API. 这适用于Directions JavaScript网站服务和Maps JavaScript API中的路线服务。

Here is an example for the web service, you'll see fare info (right after "copyrights") once you add your own API (Server) key: 以下是Web服务的示例,添加自己的API(服务器)密钥后,您将看到票价信息(在“版权”之后):

https://maps.googleapis.com/maps/api/directions/json?origin=NE+Fremont+and+80th+Portland+OR&destination=Portland+OR&mode=transit&departure_time=1466096686 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 for the JavaScript API: http://jsbin.com/rumugu/edit?html,output 以下是JavaScript API的示例: http//jsbin.com/rumugu/edit?html,output

  • if you put your (Browser) API key, you'll see "2,50 $" pop-up 如果你放入(浏览器)API密钥,你会看到“2,50 $”弹出窗口

  • if you remove the key= parameter altogether, "undefined" will pop-up 如果你完全删除key =参数,将弹出“undefined”

[1] Maps API for Work and Premium Plan customers can also use their Client ID. [1] Maps API for Work和Premium Plan客户也可以使用其客户ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM