简体   繁体   English

我如何从经度和纬度获取地址位置

[英]How i can get al the address location from latitude and longitude

i already have the latitude and longitude, i am getting almost all the location but the postalcode is always null, and the address give the street name and number i want this separate. 我已经有了纬度和经度,几乎可以找到所有位置,但是邮政编码始终为空,并且地址给出了我想要分开的街道名称和编号。 Well this is my code... thanks for your help.. 好吧,这是我的代码...感谢您的帮助。

Geocoder geocoder;
          List<Address> addresses;
          geocoder = new Geocoder(this, Locale.getDefault());
          try {
            addresses = geocoder.getFromLocation(lat, lng, 1);
            Address ad = addresses.get(0);
               address = ad.getAddressLine(0);
               country = ad.getCountryName();
               postalcode = addresses.get(0).getPostalCode();
               city = ad.getLocality();
               state = ad.getAdminArea();

Yes, Geocoder Address returns null for fields if it doesn't have value for particular field. 是的,如果Geocoder地址没有特定字段的值,则该字段返回null。 Like you are getting null of postal code. 就像您得到的邮政编码为空。 Always do null check before using field value from Geocoder Address list. 在使用Geocoder地址列表中的字段值之前,请务必先执行null检查。

What you're trying to do is called reverse geo-coding and you'll need to use a 3rd party service to be able to do this. 您尝试做的事情称为反向地理编码,您需要使用第三方服务才能做到这一点。 Have a look at these links here . 这里看看这些链接。

Some of these services produce better results than others, but you can't rely on them. 其中一些服务会比其他服务产生更好的结果,但是您不能依靠它们。 If you get a result back (or a partial one as you have) then great. 如果您得到了一个结果(或者您得到了一部分),那就太好了。 But expect that you might not get anything back at all. 但请期待您可能什么也得不到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM