当我有位置的经度和纬度时,我试图从 android 中的 google maps api 中找出位置名称。我想要实现的是,在获得位置名称后,我想向我的朋友发送一条短信,告诉他们我当前的位置。我不确定是否需要打开地理编码器服务。
这就是我到目前为止所做的,现在我卡住了。
class mylocationlistener implements LocationListener
{
@SuppressLint("NewApi")
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if(location != null)
{
Double longi = location.getLongitude();
Double lat = location.getLatitude();
String str = "";
str= "Longitude=" + longi + ", Latitude=" + lat;
Toast.makeText(getApplicationContext(),str,Toast.LENGTH_LONG).show();
Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
boolean abc = Geocoder.isPresent();
try {
List<Address> addresses = geocoder.getFromLocation(lat, longi, 1);
if(!addresses.isEmpty())
{
str = addresses.get(0).getLocality() + addresses.get(0).getAddressLine(1)+ addresses.get(0).getAddressLine(2);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Toast.makeText(getApplicationContext(),str, Toast.LENGTH_LONG).show();
}
}
}