i am trying to get user geoLocation by his Ip , so i tried calling googleapi inside my lambda function
const getLatLng = () => axios
.post(`https://www.googleapis.com/geolocation/v1/geolocate?key=${key}`)
.then(({ data }) => data);
Now the strange part is, when I run my node project locally and call the endpoint, it works really good and it detect my ip and return my correct lat and lng - then I use the same code after I deploy the service to api gateway in aws, and it return my lat lng wrong, so the request works but the value is wrong.
Does anyone know what might be the reason? Is it true that i should call googleapi from my client and pass lat and lng to my server and then use them for my other calculations and stuff i ineed ?
Google Geolocation works based off of the device / IP you are requesting from.
If you request that information from an AWS instance, it will give you its best guess at where that AWS server is physically located. In this situation, Google has absolutely no idea who the client is or that you want their location information, and would have no way to get that.
You should use geolocation from the client-side and pass that data to your server, or use a different service that can perform geolocation based on the IP your server sees the client's request as coming from.