Geocoder locale language always return english - android

I try get city according to current location with specific language i do that before like below and all work good but in my new project its not work!
Geocoder geo = new Geocoder(getApplicationContext(), new Locale("ja"));
List<Address> addresses = null;
try {
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0) {
Log.d("CITY",addresses.get(0).getLocality());
city.setText(addresses.get(0).getLocality());
} else {
// do your stuff
}
} catch (IOException e) {
e.printStackTrace();
}
dos not matter which language be set always name of city return with English language!

after some research i understand must set geo.getFromLocation maxResults > 1 cause always first address returned in list , return with English language but the next items will be your specific language , so just need change
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
to
addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 2);
and getLocality like this addresses.get(1).getLocality()

Related

getFromLocation returns null

I want to get the current location for android with out using Google APIs Key that's why
I'm Using the Geocoder.
It is working absolutely for many devices but it not for some selected devices like Latest android version_12 and in OnePlus_v10,11,12.
if (Geocoder.isPresent())
{
try
{
Geocoder geocoder = new Geocoder(contex, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);
if (addresses.size() > 0)
{
cityName = addresses.get(0).getAddressLine(0);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
Please provide the solution for the same share with someone you know who can fix it.
Also is there any changes in new android device regarding GPS,WI-FI, Network Checker.

How to get the home/work address from android maps 2 sdk

When I go maps|settings|edit home or work I see my home & work address, cool!
Anybody know how to get that same information from the Android SDK? I am working on a maps app and would like to plot those to points of reference, with out asking the user for them again?
Thanks
You will need to use reverse geocoding to convert the latitude/longitude into an address. More info about geocoding can be found here.
Here is an example:
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
String result = null;
try {
List<Address> list = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 1);
if (list != null && list.size() > 0) {
Address address = list.get(0);
// sending back first address line and locality
result = address.getAddressLine(0) + ", " + address.getLocality();
}
} catch (IOException e) {
Log.e(TAG, "Impossible to connect to Geocoder", e);
}

Can't get the Address from Geocoder

I have created simple code just for getting address from string location. Code brakes at starred line. Why ?? if I print the exception : Service not Available
List<Address> address;
String myAddress = "Vilnius";
Geocoder coder = new Geocoder(getApplicationContext(), Locale.getDefault());
System.out.println("coder : :" + coder);
**address = coder.getFromLocationName(myAddress, 1);**
ObjLoc1adr = coder.getFromLocationName(ObjLoc1String, 1);
ObjLoc2adr = coder.getFromLocationName(ObjLoc2String, 1);
Because of this you should always wrap that code in a try block to catch an IOException. There is no guarantee that the Geocoder always find a location or the service is reachable. This hasn't to be a fault of your code or device. A simple connection problem or timeout is enough to brake your App.
To be save have something like this:
if(GeoCoder.isPresent()) {
Geocoder geocoder = new Geocoder(this);
String myAddress = "Vilnius";
List<Address> addresses = null;
try {
address = geocoder.getFromLocationName(myAddress, 1);
if (!addresses.isEmpty()) {
Address address = list.get(0);
// do something with your address
} else {
// No results for your location
}
} catch (IOException e) {
e.printStackTrace();
}
}

how to convert the latitude and longitudein to postal address

how to convert the latitude and longitude in to postal address. i am not possible to use mapview to get geopoint.I wanted to convert latitude and longitude in address without use of mapview
This is called Reverse Geocoding, there are number of services that you can use including Google, Yahoo and Bing
See this article for free Geocoding services
Android has GeoCoder class for this :
public String getAddress(double latitude, double longitude){
if (Geocoder.isPresent()) {
try {
Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude,longitude,1);
if(addresses != null && addresses.size() > 0) {
Address first = addresses.get(0);
StringBuilder sb = new StringBuilder();
if(first.getMaxAddressLineIndex() > 0){
sb.append(first.getAddressLine(0) + ", ");
}
sb.append(first.getLocality() + ", ");
sb.append(first.getCountryName());
return sb.toString();
} catch (Exception e) {
Log.e("MyAPP", "Reverse geo lookup failed", e);
return "Unavailable"
}
} else {
return "unavailable";
}
}
Go to project properties > Android > set project build target to Google

How to get latitude/longitude based on entered address in android?

I wanna draw a route on the basis of the entered source & destination address. I need to get lat/log on the basis of address to draw a map in android. So how can i get lat/log on the basis of entered address.
Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocationName("Loc",1);
String add = "";
if (addresses.size() > 0)
{
add = addresses.get(0);
}
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();
} catch (IOException e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
Use the Google Geocoding API to get coordinates for an address: http://code.google.com/apis/maps/documentation/javascript/services.html#Geocoding

Categories

Resources