Search code examples
geolocationkrl

How can I get a users location in a KRL rule?


How can I get a users location in a KRL rule?

  • What is the method?
  • What is the advantage or disadvantage of using that method?

Solution

  • Here is a simple example

    rule locations is active {
         select using ".*" setting ()
         pre {
           whereareyou = location:region();
           msg = << 
             #{whereareyou}    
           >>;
         }
         notify("I think you live in", msg) with sticky = true;
     }
    

    And here is the docs. http://docs.kynetx.com/docs/Location

    The issue you will find is that sometimes the ip does not really represent the real location of the user because the user could be using a proxy. Also with most ISP's the ip is registered to a location a the and ISP's hub not the direct location of where the IP is being used at any given moment.

    With the advent of html 5 and location apis in the browser it may be posable in the future to get a more exact location but that has not been implemented in KRL as of yet.