How to get country code from country name - flutter

I want to get the country code by passing in the country name.
For example I have the country Canada, I want to get the country code CA.
I need this conversion because I want to use a country flag flutter package that gets the flag based on the passed in country code.
I know I can hard code a map that will do this conversion for me but I am looking for something simpler

If you are allowed to, maybe you can parse the json from a metadata tool, like DataHub? CSV.

Related

Get state and country with suburb data

So I am trying to download from openstreetmap the list of suburbs in Australia. However I am noticing that they don't seem to store the data in away that would be classified as search friendly.
for example the properties part if the following suburb only includes the local_name, it does not include the state - technically it does by referring to ref:psma:loc_pid
Howeever it's not search friendly because no one is going to search loc_pid numbers - Also it would require another database with loc_pid matches, which I don't see as helpful.
"properties":{"osm_id":-11690275,"boundary":"administrative","admin_level":10,"parents":"-11690291,-2316598,-80500","name":"Kimbolton","local_name":"Kimbolton","name_en":null,"all_tags":{"name":"Kimbolton","place":"locality","boundary":"administrative","way_area":"0.585159","wikidata":"Q55772085","admin_level":"10","ref:psma:loc_pid":"WA1703"}}}
So how can I get boundary information with State and Country codes.

Unique Contacts by phone number android

How to filter contacts by mobile number like chat applications. If a mobile number saved in contacts database with twice by with country code and without country code. I need to merge two numbers as single contact.
For example,
I saved a contact Bala with 9876543210 and +919876543210. In this scenario i need to filter both numbers and return +919876543210 number to my app database.
You need to convert all phone numbers to E164 format (with country code, no spaces or dashes)
e.g: +12125551234
If you're targeting API level 21 and above, you can simply do:
String e164 = PhoneNumberUtils.formatNumberToE164(originalNumber, countryCode);
To get the country code, try this:
TelephonyManager telephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String countryCode = telephony.getSimCountryIso().toUpperCase();
If you're targeting api level below 21, you can use google' libphonenumber library for Android with a similar API.
If all phones are normalized into E164 format, you can remove duplicates by simply not adding a new phone to a contact in case that contact already has that phone (you might find HashMap useful for this)

Facebook API - Custom Audience from contact data

does any one has experience with using Custom Audience API in order to create audience for contact data of people outside of U.S.?
Part of the API which i refer to is: https://developers.facebook.com/docs/marketing-api/reference/custom-audience/users/
As you can see, documentation lacks of explanation in what format should be data for COUNTRY field provided. Also I don't know how to format data for ST field if the country is outside of US. Should I use some region name or just leave it blank?
I uploaded 1000 users and nobody has been recognized so I suppose that I just did not format data properly.
Sample request: payload={"schema":["FN","LN","CT","ST","COUNTRY"],"is_raw":true,"data":[["adam","nowak","wroclaw","","poland"]]}&access_token=____&format=json
As you can see I left state field blank, and provided country in English translation and lower caps. It is possible that valid value is e.g. PL a not "poland". Also any information about what should be filled in state field would help me a lot.
Thanks in advance.

How to give relation among group of NSMutableArray?

my application is world guide. there is a 4 tableview and 4 mapview.
Continent
Country
City
Place
I have taken NSMutableArray for each above item and allocate them in view did load . when Asia is selected from the Continent table then only Asian countries should display from the country array. if country is selected then only city of respective country should be display in city table view from the city array like vice for place. it's like a tree. it is too lengthy to work with an array. Please guide me if another way is exist that make this task easy.
I think the better way to implement should be:
Use NSMutableArray only to store the top level Object.
Use NSMutableDictionary to store the mid & lower level objects.
Store the NSMutableDictionary in your NSMutableArray at each index of your top level Object.
Put the key as the Continent name in top NSMutableDictionary & value as country name & follow the same for next level.
In this case, you have to maintain only a single NSMutableArray to work. No need to handle 4-5 different arrays.
Hope it works for you.
To handle the data or categorize the data with the way you have the data about all four objects is quite complex because there is no key value pair by which you can identify that which country comes under which continent and which city comes under which country and so on.
So what you have to do is, use web service by which you can fetch the categorized data.
Here is link of web service by which you can simply hit the URL and catch the XML as the response.
URL : http://ws.geonames.org/countryInfo?
Above URL gives you the XML as the response. Like this :
<geonames>
<country>
<countryCode>AD</countryCode>
<countryName>Andorra</countryName>
<isoNumeric>020</isoNumeric>
<isoAlpha3>AND</isoAlpha3>
<fipsCode>AN</fipsCode>
<continent>EU</continent>
<continentName>Europe</continentName>
<capital>Andorra la Vella</capital>
<areaInSqKm>468.0</areaInSqKm>
<population>84000</population>
<currencyCode>EUR</currencyCode>
<languages>ca</languages>
<geonameId>3041565</geonameId>
<west>1.4071867141112762</west>
<north>42.65604389629997</north>
<east>1.7865427778319827</east>
<south>42.42849259876837</south>
</country>
.
.
.
and so on...
or if you want JSON format. take the following URL :
URL api.geonames.org/countryInfoJSON?username=demo&formatted=true
So now you are just few steps away from your solution.
Now Do the XML parsing and filter the data according to your requirement.
or if you want to have the detail knowledge about this web service
just visit : http://geonames.r-forge.r-project.org/
Hope it works for you.
I suppose you have all the data about Continent, Country, City and Place. In this situation the way of connecting all 4 arrays is totally depends upon the format of data you have for displaying on TableViews.
Whether it is a array of string or array of dictionary for each item or JSON or XML.
Please tell me the data format. After that i'll try my best.

"sex" field in Users.getInfo in Facebook API

This is a noob question. According to Facebook API documentation, the sex field in Users.getInfo() function returns values based on users' locale. Hence, determine the gender of user is difficult.
Any solution suggested?
1) This isn't an elegant solution, and perhaps there's a better way that uses the API, but what if you manually created a look-up table for different values of 'sex' in different locales? You could try checking out facebook profiles of people from different countries and get the string displayed for their sex. Then, put that into some kind of dictionary data structure that allows you to grab the M-F string pair based on the locale's code (also given by getInfo()). For example en-US => (male, female), ja-JP => (男性, 女性). Of course, you could try using google translate too. After you gathered this data for a handful of the main locales, you'd be more-or-less covered. Maybe someone on the internets already has done it.
Of course, you could try emailing someone who works on the API for these values. The list of locale codes is here http://wiki.developers.facebook.com/index.php/Facebook_Locales .
2) Here is probably a better solution than (1). If you directly query the FQL User table, the value returned in 'sex' will always be English, starting from February 7 2010. More information about that is here: http://wiki.developers.facebook.com/index.php/User_%28FQL%29 . So, perhaps in the future getInfo() will return only English too. Who knows.
3) The answer to your question is also given on this existing post: Facebook FQL user table `sex` field : how to return male/female even the user is using different locale?