Call Google Maps API Web Services From Android

Apr 21, 2019

For Android, you should use

Sometimes, certain features of Web Service APIs is not available on the Android SDK.

There is a Java Client for Google Maps Services, but

The Java Client for Google Maps Services is designed for use in server applications. This library is not intended for use inside of an Android app, due to the potential for loss of API keys.

If you are building a mobile application, you will need to introduce a proxy server to act as intermediary between your mobile application and the Google Maps API Web Services. The Java Client for Google Maps Services would make an excellent choice as the basis for such a proxy server.

If you use Java Client for Google Maps Services in Android, you shall bump into the followin error

com.google.maps.errors.RequestDeniedException: This IP, site or mobile application is not authorized to use this API key. Request received from IP address 2001:e68:5447:545:8d5e:f419:589f:b731, with empty referer - issue

The easiest way to solve this issue is to implement the API call in Google Cloud Functions and Android make a HTTP request to the cloud functions (using Retrofit2 perhaps). See example of Call Google Maps Geocoding Api in Google Cloud Functions (Python).

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.