问题
i am tried up with some common set of codes, to get convert the lat long values into address. But i am unable to get that in all the time.. which would be the best option for this. I need this service should be constant. because i need to deliver this to a client.
suggest me a good solution? Should i have to buy a service from google or yahoo? Those peoples are providing separate service for this. My main question is should this "geocoder" will be ok or not??
My code is
void getAddress(){
try{
Geocoder gcd = new Geocoder(this, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(latitude, longitude,100);
Log.d("latlong value",latitude +"---"+longitude);
if (addresses.size() > 0)
{
StringBuilder result = new StringBuilder();
result.append(addresses.get(0).getCountryName());
country=result.toString();
}
}
catch(IOException ex){
}
}
回答1:
should this "geocoder" will be ok or not?
Yes it is absolutely fine to use Geocode class.
Try out this very simple code,
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.getDefault());
addresses = geocoder.getFromLocation(latitude, longitude, 1);
String address = addresses.get(0).getAddressLine(0);
String city = addresses.get(0).getAddressLine(1);
String country = addresses.get(0).getAddressLine(2);
来源:https://stackoverflow.com/questions/21930665/how-to-get-address-of-a-location-from-latitude-longitude-values-using-geocoder-i