Forum Discussion

radhika_kundana's avatar
3 years ago

How to retrieve user location using IP address

hi,

I was able to retrieve IP address using ${http.request.remoteAddr}.

What is the approach to retrieve user location in Khoros for both logged in and anonymous users? 

  • Hi radhika_kundana!

    Glad that you were able to retrieve the IP address using ${http.request.remoteAddr}.

    There are multiple approaches such as you could try using FreeMarker with API v2 underlocation and last_visit_ipaddress:
    https://developer.khoros.com/khoroscommunitydevdocs/docs/gdpr-support

     

    You could also use our Bulk Data API under request.geo.cityrequest.geo.country:
    https://developer.khoros.com/khoroscommunitydevdocs/reference/bulk-data-api#export-reference 

     

    Or, you could go the custom route through services like here

     

    I hope this helps!

  • thankyou MohammedF for details. 

    VarunGrazitti  We have below requirements for geo location and its for all users. I would like to check if below functionality is already available. 

    1. Show(detect) current location in text field as water marker text

    2. When user types in location text field, auto suggest places. 

    We are also planning to develop a component to filter the events or group of selected location. 

    Any details will be helpful.

    Thankyou,

    Radhika

    • VarunGrazitti's avatar
      VarunGrazitti
      Boss

      radhika_kundana - I don't think these are available OOTB, since the OOTB APIs only give you the IP, however, both could be achieved via some custom snippets and using some 3rd party API to detect the locations based on these IPs.

       

      I hope this helps.

  • @VarunGrazitti  I am able to retireve current user location by calling bing api in ajax. 

    but when I try to call bing api in endpoint, it gives incorrect user location.

    I would like to know if below code is correct  to call external api in endpoint:

    <#assign response = http.client.request("https://www.bing.com/api/v7/userlocation?appid=xyz1234").get()/>

    <#if response.hasError>
    ${response.error.message}
    <#else>
    ${response.content}
    </#if>

  • Hi radhika_kundana,

    In order to successfully call the Bing API in FreeMarker, you'll first need to go into Community Admin > System > HTTP Client and add bing.com to the Allowed domain names field.

    Hope this helps.

  • jeffshurtliff sorry for the confusion, I am still seeing the same issue.

    bing api with ajax call gives me correct location where as endpoint gives me in-correct location. 

    Please suggest me if there is an way to fix this bug. 

     

    • radhika_kundana's avatar
      radhika_kundana
      Ace

      jeffshurtliff 

      I was able to make it work by passing ip address in headers.

      <#assign response = http.client.request("api").header("X-FORWARDED-FOR",ipaddress).get()/>

      Will there be any privacy or security issues in passing IPaddress in headers?