google-apigoogle-geolocation

Google geolocation api returns server location where the app is deployed


Apologies if this is weird question, but I've been trying to resolve this for a long time and I can't figure out and am little frustrated.

I'm developing a webapp and need to use Google geolocation API (I'm aware of HTML5 geolocation api but it's not for my use case). when developing locally the api returns lat/long with big accuracy number. that's because I set considerIp to true. which is completely fine, at least I can detect the city.

That being said, when I deploy my app to real servers and test it via phone, it returns east coast locations!! I'm sure api can't figure out and falls back to ip detection.

So what is the use of geolocation api? is it not for client side development? Certainly I can't include cellTowers or wifiAccessPoints in the request body since it's not possible to detect those on client. and documentation on this api is poor.

I'm trying to accomplish user approximate location for better app experience. Is this achievable via google geolocation api?

Many thanks.

PS. I know about other geolocation services that uses IP lookup, maybe they will be my last resort.


Solution

  • Assuming you are referring to this Google Maps Geolocation API, please make sure your client is invoking the HTTP GET request to the www.googleapis.com API endpoint, and not the server. That should help the API backend detect your client's public IP address correctly for the considerIp configuration.