716
Views
9
Comments
How to get the user's location ?
Question

Hi !

In my web application, I want to be able to default the user's location (country).  Is this possible and what is the best way to do this ?

I've thought about using the HTTP Request Handler 'GetIP' function to obtain the client IP address and then use a Forge component (any recommendations ?) to obtain the location information from that.  That may hit problems if the user is using a VPN, but I'm not sure there are any foolproof solutions to this requirement.

Any other suggestions ?

Cheers, Richard

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi,

Not a lowcode answer, sorry.

You can use your IP address to get your 'country', 'city', 'isp' etc...
Just use one of the web-services that provide you with a simple api like http://ip-api.com which provide you a JSON service at http://ip-api.com/json. Simple send a Ajax (or Xhr) request and then parse the JSON to get whatever data you need.

var requestUrl = "http://ip-api.com/json";

$.ajax({
  url: requestUrl,
  type: 'GET',
  success: function(json)
  {
    console.log("My country is: " + json.country);
  },
  error: function(err)
  {
    console.log("Request failed, error= " + err);
  }
});
2024-04-08 10-59-50
Pedro Sismeiro

Does anyone know of a free for business API alternative?

UserImage.jpg
Jay ar Viluan

Hi Richard,


Your question is answered here:

https://www.outsystems.com/forums/discussion/34093/get-location/


Thanks

2019-09-24 18-41-25
Jorge Martins
 
MVP

Jay ar Viluan wrote:

Hi Richard,


Your question is answered here:

https://www.outsystems.com/forums/discussion/34093/get-location/


Thanks


Jay ar Viluan,

I thought as much, but upon experimenting with it, there's a big downside to it. Using that approach you will need the users' permission to determine their location, using something like an IP to Country/Location web API you don't and you still get the information you need (which country are they accessing your app.

2019-05-02 05-10-57
Richard Pearce

Jorge Martins wrote:

Jay ar Viluan wrote:

Hi Richard,


Your question is answered here:

https://www.outsystems.com/forums/discussion/34093/get-location/


Thanks


Jay ar Viluan,

I thought as much, but upon experimenting with it, there's a big downside to it. Using that approach you will need the users' permission to determine their location, using something like an IP to Country/Location web API you don't and you still get the information you need (which country are they accessing your app.

Hi Jorge,

Yes, that is what I thought.  Any recommendations on which Forge component or external API to use to return the country/location for an IP address ?

Cheers, Richard.

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

I did suggest such and API in my previous post.

I past in a JavaScript example on how to consume it, as that was the only way I have used it.

But of course you can consume the API also on the logic tsb in OutSystems, should be easy.

http://ip-api.com/docs/dns

2025-11-19 06-14-01
Miguel Verdasca
Champion

Hello,

You can take a look at this component: 

Kind regards,
Nuno Verdasca

2020-02-28 09-46-54
Eduardo Jauch

Hi Nuno,

The OP questioned about web applications, not mobile.

"In my web application, ..."

Cheers.

2024-04-08 10-59-50
Pedro Sismeiro

Any ideas on how to get just the ISP name?

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.