【问题标题】:Problems with LocationManager Android 4.4.1LocationManager Android 4.4.1 的问题
【发布时间】:2014-06-26 13:57:32
【问题描述】:

我想在我的应用中获取用户的当前位置。每次我使用LocationManager 都会出现这个错误:

LocationManager 类型中的 requestLocationUpdates(String, long, float, LocationListener) 方法不适用于参数(String, int, int, MainActivity)。

这是我的代码:

public class MainActivity extends ActionBarActivity implements LocationListener
{
    private GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
              //I get error in this line            
          locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

    }

    @Override
    protected void onResume() 
    {
        super.onResume();
    }

    @Override
    public void onLocationChanged(Location location) 
    {
        // TODO Auto-generated method stub
        double latitude = (double) (location.getLatitude());
        double longitude = (double) (location.getLongitude());
        Log.i("Geo_Location", "Latitude: " + latitude + ", Longitude: " + longitude);
    }

}

LocationListener 实现也会给我一个错误,必须像这样实现android.location.LocationListener

任何帮助我都会非常感激。

PD:我正在使用 Eclipse

【问题讨论】:

    标签: android geolocation locationmanager android-location


    【解决方案1】:

    自从我使用任何 android 东西以来已经有很长时间了,但去年构建了一个位置应用程序,这就是我实现位置侦听器的方式,并且一切正常。

    problems with android.location.geocoder

    注意:并非链接中的所有代码都与您的问题相关,但结构可能会有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-03-02
      • 1970-01-01
      • 2012-08-26
      • 1970-01-01
      • 1970-01-01
      • 2013-03-18
      • 2019-06-29
      • 1970-01-01
      相关资源
      最近更新 更多