【发布时间】: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