我尝试使用一些常见的代码集,将纬度长值转换为地址。但我无法一直得到它..这将是最好的选择。我需要这个服务应该是恒定的。因为我需要把它交付给客户。
建议我一个好的解决方案?我应该从谷歌或雅虎购买服务吗?这些人民正在为此提供单独的服务。我的主要问题是这个"地理编码器"应该没问题吗?
我的代码是
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){
}
}
这个"地理编码器"应该没问题吗?
是的,使用地理编码类绝对没问题。
试试这个非常简单的代码,
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);