Assuming that I don't know my current location, how to move MapView to country by it's name?
What I'm trying to do is display user's country by country code in locale.
There isn't such a table in android with a link between country and geolocation that I'am aware of.
I believe the best approach is to get a list of all capital cities with latitude and longitude (you can get them here : list of capital cities) or a list of countries (you can get them from here : list of countries) and put it in a table in your application.
good luck.
Yes you can display User's country by Country Code.
As we have facility to get the CountryCode through Android Telephony Manager Api so.
1)You have to use Key Value pairs concept, Key as CountryCode and Value as Country.
like the following code:
TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
manager.getNetworkCountryIso();
Related
I'm trying to get the country language of the user, not the selected one on the phone.
For example:
I'm building an English learning app, but in my phone I've set language to English for learning purposes, and it doesn't translate because it thinks that my language is English, but I live in brazil, I want it to find that my language is Portuguese. to get languages by especific location.
I have tried some codes, but not seems to work.
I have many users in my app that have English language on phone, so they are facing the same problem.
var currentLanguage: String = Locale.getDefault().language
var language = this.getResources().getConfiguration().getLocales().get(0).language
They both give me the same value, that my language is english, and if I get the country it says I'm in US.
EDIT:
I'm able to get the country code with it:
var tm = this.getSystemService(TELEPHONY_SERVICE) as TelephonyManager
var countryCodeValue = tm.networkCountryIso
It returns br, but how can I get the language from this tag?
There is something like:
countryCodeValue.language
?
Well you have it there in your own description of the problem. You want to get the language based on the country the user is in. So you need to first get the country where the user is in. So it's a location problem.
There are several options. One is to get the user's location using the last known location of the user.
Docs: https://developer.android.com/training/location/retrieve-current
The problem here is you need to then transform coordinates to country. There are some API's for this, Google maps has one.
Maybe an easier approach is to use the TelephonyManager to get the country code of the user. This also has a problem because it relies on having a sim card.
Finally you need to transform that country to a language. But you can do that with the Locale class.
IMHO, it would be easier to give your users a selector for the language, that way they can decide what language to use instead of you choosing for them based on some algorithm.
Update:
It's not that straight forward to get the language of a Country. Basically some countries have multiple official languages for example. There are other questions addressing this issue. But in short, you either have a static file mapping from country to language or you iterate over the available Locales and choose one of the languages for the country.
Here are other questions:
If you have the ISO country code `US`, `FR`, how do you get the Locale code (`Locale.US`, `Locale.FRANCE`)?
Getting default language from country code in Java
How to get the language code based on country code in java
Well guys, I did it, and its working almost as I wanted it to be.
I'll have a little work to do it for too much countries. If someone have a better Idea, I'd be glad to know. Thanks. Maybe it can help someone.
var tm = ctx.getSystemService(AppCompatActivity.TELEPHONY_SERVICE) as TelephonyManager
var countryCodeValue = tm.networkCountryIso
fun getLanguage(country: String) : String{
var current : String
when{
country.contains("br") && Locale.getDefault().language.equals("en") -> current = Locale.forLanguageTag("pt").toString()
country.contains("in") && Locale.getDefault().language.equals("en") -> current = Locale.forLanguageTag("hi").toString()
country.contains("pk") && Locale.getDefault().language.equals("en") -> current = Locale.forLanguageTag("ur").toString()
else -> current = Locale.getDefault().language
}
return current
}
var lang = getLanguage(countryCodeValue)
var tradOpt = TranslatorOptions.Builder()
.setSourceLanguage(TranslateLanguage.ENGLISH)
.setTargetLanguage(TranslateLanguage.fromLanguageTag(lang).toString())
.build()
I want to display country flags with respect to phone-numbers in my contact lists like rebtel(Screen shot shown below).
Parse the phone number and get the international prefix, then you can use Wikipedia: List_of_country_calling_codes to get the country. You can implement a Map with key being the international prefix and key the country name.
Here I am giving you the logic part,
You can get the ISD code and flag image from this link http://en.wikipedia.org/wiki/List_of_country_calling_codes#Alphabetical_listing_by_country_or_region
You need to make two Array variables,
String [] countryCode = new String { "+91","+92", ... };
int [] country = new int { R.drawable.91.png, R.drawable.92.png,.... };
// Considering here 91.png is india's map
Now get the phone number from contact list , suppose you have +91987654321. So remove first + sign and compare 91 to all the resources images. When match found, put that image with the contact.
You can use this library for your Requirement.
Go to detail you can show country flag and country code with use of this.
In my app, I have a list of locations, and I want to create filter settings. I am looking for a way so that a user can pick maybe a continent or country or address and then filter out the locations from the list if the location is within the continent or country or close to the address.
Is there a google maps v2 api for android that can do something like:
public Boolean AddressIsContained(String address, String place);
which returns true if address is within place (place could be like a country or continent). And also like
public Boolean AddressCloseTo(String address1, String address2, int distance);
which returns true if address1is within distance amount of kilometers to address2. And this would just be a straight line between the addresses, nothing like a bike, walk, car or plane route.
Also for the list of locations, I am also able to access its lat/long if that makes it easier.
Thanks
For the start I assume you are familiar with the GeoCoder and / or GeoCoding API to get the addresses for your locations.
If you use the GeoCoder you will get a List of Address objects. The Address class provides some methodes to get the country or city name f.e. These methods you can use for your filter.
The Location class includes the methods distanceBetween() and distanceTo(). These you can use to check the distance between your locations.
I can get the longitude and longitude android. And now I want to get the short country name against it. How to do that? I also have country code... All I want is to show short country name e.g "UK" , "SG" etc...
Finally I found a web-service that give 2 digit country code along with temperature.
Its very simple
http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=31.50766766,74.33741188000002
Is it possible to find Base Station Identifying Code in android. To clarify, Let 'A' calls to 'B'. Before 'B' receive the phone call, his installed app will find
'A's BSIC and match it with a given database of BSIC( this BSIC database may be located on phone locally or
in a web or from phone network provider's database ) then will find 'A' location( Say +88017... is calling from "Dinajpur of Bangladesh" ).Is it possible ? if so how ? please help me...
Rereading the question, you want the other person's tower, not your own. No, i don't think that info is available to you. At most, you can guess by the country and region codes.
Not relevant anymore:
I believe you can achieve what you want getting the cell id in use or all the neighboring cells
TelephonyManager mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
GsmCellLocation loc = (GsmCellLocation) mTelephonyManager.getCellLocation();
Log.d ("CID", Integet.toString(loc.getCid()));
Log.d ("LAC", Integet.toString(loc.getLac()));
// or
List<NeighboringCellInfo> list = mTelephonyManager.getNeighboringCellInfo ();
for (NeighboringCellInfo cell : list) {
Log.d ("CID", Integet.toString(cell.getCid()));
Log.d ("LAC", Integet.toString(cell.getLac()));
}
You can refer then to cell location through several open databases (e.g., http://www.location-api.com/ or http://opencellid.org/ )
If this is not enought, I suggest you to check this thread: http://groups.google.com/group/android-platform/browse_thread/thread/b55c8d3275ed7042/78d9c30c49e94a3a , specially this link: http://www.google.com/url?sa=D&q=http://www.3gpp.org/ftp/Specs/archive/27_series/27.007/27007-860.zip