How can I forward the client's IP Address to Google Places Autocomplete API
Currently, Google Places server-side API does not support IP address as a parameter for location biasing. So you have two options.
- Use client-side API (You have mentioned this is not feasible)
- Call a reverse geolocation API to get the country code of an IP.Then pass this country code to Google places API via components parameter.
example for Ipfind service
using (var webClient = new System.Net.WebClient()) { string ip_address = "10.23.45.154"; string URL = "https://api.ipfind.com/?ip=" + ip_address; var json = webClient.DownloadString(URL); // extract ISO country code here and call Google Places API}
components — A grouping of places to which you would like to restrict your results. Currently, you can use components to filter by up to 5 countries. Countries must be passed as a two character, ISO 3166-1 Alpha-2 compatible country code. For example: components=country:fr would restrict your results to places within France. Multiple countries must be passed as multiple country:XX filters, with the pipe character (|) as a separator. For example: components=country:us|country:pr|country:vi|country:gu|country:mp would restrict your results to places within the United States and its unincorporated organized territories.
I will assume you've already looked through official Google documentation and restricting a key to your owned domain does not suit you.
I guess then you can try calling a 3rd party API to roughly bias client IP to location and the use it for you Google autocomplete.