Вопрос

I have hosted my web-app on google appengine (GAE). Does GAE sdk offer any way to find the geolocation of an IP ? If yes please suggest how can I do this .

Это было полезно?

Решение

Yes, you can use request headers to get the geolocation of the IP.

https://cloud.google.com/appengine/docs/standard/go/reference/request-response-headers#app_engine-specific_headers

X-AppEngine-Country Country from which the request originated, as an ISO 3166-1 alpha-2 country code. App Engine determines this code from the client's IP address.

Other headers that are useful for location are X-AppEngine-Region, X-AppEngine-City and X-AppEngine-CityLatLong

I don't think this will return valid values when running on your local sdk.

Другие советы

It is not clear from your question if you want to determine location of the http request being made to your GAE application or whether you want a service on GAE that can give you the geolocation of any IP address.

GAE provides support for certain HTTP headers that contain geolocation information like country, city, region and IP address. Refer to the two articles over here for more details:

The above articles discuss the headers like

  • X-AppEngine-country
  • X-AppEngine-Region
  • X-AppEngine-City
  • X-AppEngine-CityLatLong

If you are simply looking for a service to give you geolocation details based on IP then GAE does not provide that. There are various external web services available like the one mentioned above in one of the answers.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top