如何从经纬度值,使用地理codeR android系统中的位置的地址吗? [英] How to get address of a location from latitude longitude values using geocoder in android?
问题描述
我尝试了一些共同的codeS,得到转换纬度长值到地址。但我无法得到,在所有的时间.. 这将是我们的最佳选择。我需要这种服务应该是恒定的。因为我需要提供这一个客户。
建议我一个很好的解决方案吗? 如果我不得不从谷歌或雅虎买服务? 这些国家的人民都提供单独的服务这一点。 我的主要问题是应该这样地理codeR将以好不好?
我的code是
无效的getAddress(){
尝试{
地理codeR GCD =新的地缘codeR(这一点,Locale.getDefault());
名单<地址>地址= gcd.getFromLocation(纬度,经度,100);
Log.d(经纬度值,北纬+ - +经度);
如果(addresses.size()大于0)
{
StringBuilder的结果=新的StringBuilder();
result.append(addresses.get(0).getCountryName());
国家= result.toString();
}
}
赶上(IOException异常前){
}
}
应该这样地理codeR将以好不好?
是的,它是精美绝伦使用地理code类。
试试这个非常简单的code,
地理codeR地理codeR;
名单<地址>地址;
地理codeR =新的地缘codeR(这一点,Locale.getDefault());
地址=地理coder.getFromLocation(纬度,经度,1);
串地址= addresses.get(0).getAddressLine(0);
串城市= addresses.get(0).getAddressLine(1);
串国= addresses.get(0).getAddressLine(2);
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){
}
}
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);
这篇关于如何从经纬度值,使用地理codeR android系统中的位置的地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!