机器人:反向地理编码 - getFromLocation机器人、地理、getFromLocation

2023-09-12 21:30:56 作者:别让梦想只是梦想

我想基础上,经度/纬度来获得一个地址。看来,这样的事情应该工作?

I am trying to get an address based on the long/lat. it appears that something like this should work?

Geocoder myLocation = Geocoder(Locale.getDefault());
    List myList = myLocation.getFromLocation(latPoint,lngPoint,1);

问题是,我不断收到:该方法地理codeR(区域)是未定义的类型savemaplocation

The issue is that I keep getting : The method Geocoder(Locale) is undefined for the type savemaplocation

任何援助将是有益的。谢谢你。

Any assistance would be helpful. Thank you.

谢谢,我试过的背景下,区域设置一个第一,那失败,并寻找一些其他的构造函数(我看到了一个曾经提到刚刚区域)。无论如何,

Thanks, I tried the context, locale one first, and that failed and was looking at some of the other constructors (I had seen one that had mentioned just locale). Regardless,

它没有工作,因为我仍然得到:该方法地理codeR(背景下,区域设置)是未定义的类型savemaplocation

It did not work, as I am still getting : The method Geocoder(Context, Locale) is undefined for the type savemaplocation

我有:进口android.location.Geo codeR;

I do have : import android.location.Geocoder;

推荐答案

以下code段是做什么的,我(纬度和经度双打高于此位宣告):

The following code snippet is doing it for me (lat and lng are doubles declared above this bit):

Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(lat, lng, 1);