简体   繁体   中英

Duration in traffic from android app

I am trying to get response from Google Directions API including duration_in_traffic . In documentation to response there are conditions for this value to be included, one of them is

The request includes a valid Google Maps API for Work client and signature parameter.

If I understand google APIs correctly, the client+signature is authentication scheme used in server-server (web-service) calls and it would be bad idea to include cryptographic key into mobile app to generate signature.

So, how to get duration_in_traffic in response from request generated from android app? Can I somehow make it work by using Key for Android applications form Google Developer console? Assuming I need "Google Maps API for Work", how can I enable it for my Google developer console account?

Definite answer from Google Maps for Work support:

The duration in traffic is currently only available to authenticated Maps for Work requests, those that include a client ID and signature. Unfortunately it is not possible to have this returned when requesting directions in any other way. Additionally it is not possible to place requests to any of the Web Services using an Android or iOS key. These only function with the respective mobile APIs.

If you want to place requests for directions from a mobile device the advisable way to achieve this is to proxy your request via one of your own servers. Essentially the device sends the request to the server (with some form of authentication if you so desire) and the server then sends the Maps for Work request to us. Once it receives the response this is sent back to the mobile device. By doing it this way you do not expose your crypto key in order to mke the requests.

TL;DR: No way to use from android app, you must use your server as proxy and implement own authentication (and rate limiting, throttling, etc.) to mind your quotas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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