private class ButtonListener implements OnClickListener
{
@Override
public void onClick(View v) {
//得到LocationManager对象
LocationManager locationManager=(LocationManager)MainActivity.this.getSystemService(Context.LOCATION_SERVICE);
//定义当前所使用的Location Provider
//第二个参数:隔多少秒更新一次 第三个参数:隔多少距离更新一次
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5000, new TestLocationListener());
private class ButtonListener implements OnClickListener
{
@Override
public void onClick(View v) {
//得到LocationManager对象
LocationManager locationManager=(LocationManager)MainActivity.this.getSystemService(Context.LOCATION_SERVICE);
//定义当前所使用的Location Provider
//第二个参数:隔多少秒更新一次 第三个参数:隔多少距离更新一次
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 5000, new TestLocationListener());
}
}
class TestLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location location) {
System.out.println("onLocationChanged");
System.out.println(location.getLongitude());//获取经度
System.out.println(location.getLatitude());//获取纬度
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
System.out.println("onStatusChanged");
}
@Override
public void onProviderEnabled(String provider) {
System.out.println("onProviderEnabled");
}
@Override
public void onProviderDisabled(String provider) {
System.out.println("onProviderDisabled");
}
}