Getting the users country
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Getting the users country
Is there an easy way to get the users country from the app store or something similar within livecode ios.
Im working on an app that has a regional database, depending on which country the user is in and if possible I would like to pre-fill the country when I ask them as part of the user setup what country they are in.
Thanks
Andy
Im working on an app that has a regional database, depending on which country the user is in and if possible I would like to pre-fill the country when I ask them as part of the user setup what country they are in.
Thanks
Andy
Re: Getting the users country
Hmmm, as far as I know LiveCode has no automatic way of doing this, but I may be wrong.
I'm pretty sure no App Store will give you information on logged in users - but it is possible in Swift and other languages to get a country code associated with the App Store used. This is an informative post: https://stackoverflow.com/questions/493 ... re-country
how this can be applied in LC I'm not sure - but presumably if you're using the App Store to distribute, you may have access to the API.
Alternatively perhaps you could IP geocode users when using the app (although you'd need to clarify this in your EULA and/or seek consent).
If you did go down that route there are a number of alternatives - https://radar.com/product/api?utm_term= ... HxEALw_wcB might be a good one as it's free for up to 100,000 API calls per month and seems relatively cheap if you exceed that limit. You could use its IP geocode API to get the user's location - but that assumes of course they are not on a VPN (but then they may well be using a different country's App Store).
Or you could just get this information directly from the user
I'm pretty sure most users are used to entering a country name - I certainly am
I'm pretty sure no App Store will give you information on logged in users - but it is possible in Swift and other languages to get a country code associated with the App Store used. This is an informative post: https://stackoverflow.com/questions/493 ... re-country
how this can be applied in LC I'm not sure - but presumably if you're using the App Store to distribute, you may have access to the API.
Alternatively perhaps you could IP geocode users when using the app (although you'd need to clarify this in your EULA and/or seek consent).
If you did go down that route there are a number of alternatives - https://radar.com/product/api?utm_term= ... HxEALw_wcB might be a good one as it's free for up to 100,000 API calls per month and seems relatively cheap if you exceed that limit. You could use its IP geocode API to get the user's location - but that assumes of course they are not on a VPN (but then they may well be using a different country's App Store).
Or you could just get this information directly from the user
I'm pretty sure most users are used to entering a country name - I certainly am
Re: Getting the users country
Thanks
Ive found a command mobileCurrentLocale() which gives a good indicator as to the country the user is in so this is a good starting point for my drop down box, I can detect a US or GB language and set the country initially to that, beyond that the user will have to select the country themselves.
Thanks for the help.
Ive found a command mobileCurrentLocale() which gives a good indicator as to the country the user is in so this is a good starting point for my drop down box, I can detect a US or GB language and set the country initially to that, beyond that the user will have to select the country themselves.
Thanks for the help.
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Getting the users country
"a US or GB language" ?
Let's see: US English, GB English, Welsh, Irish Gaelic, Scots Gaelic, Spanish, Pennsylvania Dutch, Louisiana French, Gullah, . . .
What about other languages?
Let's see: US English, GB English, Welsh, Irish Gaelic, Scots Gaelic, Spanish, Pennsylvania Dutch, Louisiana French, Gullah, . . .
What about other languages?
Re: Getting the users country
The OP wishes to pre-populate a database based on App Store location, with the user being able to fill in detail.richmond62 wrote: ↑Mon Aug 07, 2023 2:57 pm"a US or GB language" ?
Let's see: US English, GB English, Welsh, Irish Gaelic, Scots Gaelic, Spanish, Pennsylvania Dutch, Louisiana French, Gullah, . . .
What about other languages?
It's not a language thing. I'm guessing you just read the last sentence of the last post, didn't you?
How does the OP's question and aim apply to Welsh, Irish, Scots, Gaelic 'Louisiana French', Gullah (you really excelled yourself on that one...)? Is there a Gullah app store that I missed? Does this really help in any way?
As my great-grandma used to say: don't feed the trolls, so I'll stop there...
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Getting the users country
I wonder what the Gullah for 'troll' is?
How about getting the stack to determine the device's external IP address?
https://forums.livecode.com/viewtopic.php?t=29919
How about getting the stack to determine the device's external IP address?
https://forums.livecode.com/viewtopic.php?t=29919
Re: Getting the users country
Richmond, that was implied when I suggested one option is to IP geocode.richmond62 wrote: ↑Mon Aug 07, 2023 4:33 pmI wonder what the Gullah for 'troll' is?
How about getting the stack to determine the device's external IP address?
https://forums.livecode.com/viewtopic.php?t=29919
Getting the IP is not hard, it's what you do with it.
I linked an API that allows 100,000 free API calls for geolocation by IP per month - and assuming this is a process for initial installation/registration I can't really imagine that wouldn't suffice and be done entirely for free - but that does add a level of complexity which probably isn't needed as Andy is happy just to use the country code returned by the App Store.
Now if he wanted to automatically get City, State and Country then the IP geolocation API would be more useful...
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Getting the users country
yes - the API for that is found here: https://airvpn.org/forums/topic/14737-api/
+ free, seems to work
- judging by forums, occasionally spotty performance
- less documentation/support than commercial service (even if free)
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Getting the users country
I wonder why this returns NOTHING when the original line refered to contains data?
Code: Select all
find "continent_name" in fld "dLIST"
put line (the foundLine) of fld "dLIST" into fld "bilad"
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Getting the users country
Mind you, if I could import a URL into a text field like this:
- -
instead of like this:
- -
'Life' would be a whole lot easier.
- -
instead of like this:
- -
'Life' would be a whole lot easier.
Re: Getting the users country
the foundLine is a chunk expression, ie line x of field y, but annoyingly if you try to use this directly (ie put the FoundLine into field "blah") it literally just puts "line x of field y" into field "blah".richmond62 wrote: ↑Tue Aug 08, 2023 7:57 amI wonder why this returns NOTHING when the original line refered to contains data?
Code: Select all
find "continent_name" in fld "dLIST" put line (the foundLine) of fld "dLIST" into fld "bilad"
So you could either change your code to:
Code: Select all
put line (word 2 of the foundLine) of fld "dLIST" into fld "bilad"
Code: Select all
put value(the foundLine) into fld "bilad"
As usual my preference is different: Since the data returned is in JSON format, which is basically a textual representation of a multidimensional array, I would prefer to put this into an array and get it's key - no need to faff around with extra and unnecessary fields and no need to 'clean' the text.
Code: Select all
on mouseUp
local tArray
put JSONToArray(URL ("https://ipleak.net/json/")) into tArray
put tArray["continent_name"] into field 1
end mouseUp
Wheres the array just it returns the value and populates the field with Europe
Last edited by stam on Tue Aug 08, 2023 10:20 am, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Getting the users country
Your value in my eyes would have dropped considerably had it not been.As usual my preference is different
HOWEVER . . . my mind has wandered to the question I posted just before your reply.
After all, if Mac's 'happy, little' TextEdit can do that, surely LC can do that as well.
Re: Getting the users country
Ermm... are you just scraping the HTML?richmond62 wrote: ↑Tue Aug 08, 2023 10:03 amMind you, if I could import a URL into a text field like this:
<snip>
'Life' would be a whole lot easier.
You do realise they provide an API for easy developer access so you don't have to scape the HTML? The JSON I mentioned?
Did you spot the code I used:
Code: Select all
put JSONToArray(URL ("https://ipleak.net/json/")) into tArray
The text you get back is in JSON format:
(don't care about sharing details here as its the public wifi at my workplace)JSON wrote:{
"as_number": 15404,
"isp_name": "COLT Technology Services Group Limited",
"country_code": "GB",
"country_name": "United Kingdom",
"region_code": "ENG",
"region_name": "England",
"continent_code": "EU",
"continent_name": "Europe",
"city_name": "London",
"postal_code": null,
"postal_confidence": null,
"latitude": 51.5088,
"longitude": -0.093,
"accuracy_radius": 10,
"time_zone": "Europe\/London",
"metro_code": null,
"level": "min",
"cache": 1691487314,
"ip": "161.17.0.123",
"reverse": "",
"query_text": "161.17.0.123",
"query_type": "myip",
"query_date": 1691487314
}
-
- Livecode Opensource Backer
- Posts: 9454
- Joined: Fri Feb 19, 2010 10:17 am
- Location: Bulgaria
Re: Getting the users country
That is fantastic: thank you so, very, very much.
More like 'scraping the barrel' in my case: or, put another way: Richmond's ignorance in matters such as JSON.Ermm... are you just scraping the HTML?