Get user country?
Hi,
Is it possible to get the users country without performing a geocode request?
In my app I want to have some default settings if the users is from the us (imperial system) and if from any other country I want to use the metric system as default.
It would be great if I could know the region format the phone (iphone) is set to or something like that. If not I guess I could always perform a geo request to determine the country.
3 Answers
-
I'm looking for the same thing. There is a way to do it on the iPhone in object-c so hopefully if not already, the Appcelerator team will look into an implementation. I'm guessing there is a similar way on the Android.
I realize I'm posting Objective-C, but just in case an Appcelerator developer decides to implement it, I'll put a couple ways I've seen to do it….
Method 1:
NSLocale *locale = [NSLocale currentLocale]; NSString *countryCode = [locale objectForKey: NSLocaleCountryCode]; NSString *countryName = [locale displayNameForKey: NSLocaleCountryCode value: countryCode];
Method 2: (iOS 4+)
#import <CoreTelephony/CTTelephonyNetworkInfo.h> #import <CoreTelephony/CTCarrier.h> CTTelephonyNetworkInfo *netInfo = [[CTTelephonyNetworkInfo alloc] init]; CTCarrier *carrier = [netInfo subscriberCellularProvider]; NSString *mcc = [carrier mobileCountryCode];
-
Maybe you can open a hidden webview including MaxMind JS api:
http://www.maxmind.com/app/javascript
Example:
Country Code: TR
Country Name: TurkeySource code:
<script language="JavaScript" src="http://j.maxmind.com/app/country.js"></script> <br>Country Code: <script language="JavaScript">document.write(geoip_country_code());</script> <br>Country Name: <script language="JavaScript">document.write(geoip_country_name());</script>
-
I was hoping to be able to do this without the need to perform a web request. If I need to do this I would use the google geocoding service which turns a lat,lng from the gps into a location: http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true
I guess this might be the way to go for me.