如何在单击按钮时检索位置

时间:2014-05-03 12:22:14

标签: android locationmanager android-location locationlistener

我希望能够做到这一点:

我有TextViewButton。当我点击Button时,TextView的文字应设置为我当前所在地的名称。

我找到了一些使用LocationManagerLocationListener的示例,但似乎LocationListener听取了onLocationChanged

关于如何实现我想做的任何想法?

2 个答案:

答案 0 :(得分:0)

请使用google map api获取当前位置,然后从给定的lat long打印该位置的地址。我知道它不是详细的答案,但确定它会为你提供开始解决问题的提示。

答案 1 :(得分:0)

尝试这是最好的方法来做到这一点........

LocationManager mLocManager =(LocationManager)getSystemService(Context.LOCATION_SERVICE);                 LocationListener mLocListener = new MyLocationListener();                 mLocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,mLocListener);

public class MyLocationListener实现了LocationListener {

    public void onLocationChanged(Location loc) {           
        String message = String.format(
                    "New Location \n Longitude: %1$s \n Latitude: %2$s",
                    location.getLongitude(), location.getLatitude()
            );
            Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show();
    }
    public void onProviderDisabled(String arg0) {

    }
    public void onProviderEnabled(String provider) {

    }
    public void onStatusChanged(String provider, int status, Bundle extras) {

    }       
}
相关问题