1

恢复出厂设置后,我的设备在获取当前位置的坐标时出现问题。我检查了设置中的位置服务,一切似乎都很好。

在此处输入图像描述

我使用了相同的代码,并且在我恢复出厂设置之前它工作正常。下面是我获取坐标的代码

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

      LocationListener mlocListener = new MyLocationListener();
      mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);

public class MyLocationListener implements LocationListener
{

  @Override
  public void onLocationChanged(Location loc)
  {

   latitude =  loc.getLatitude();
   longitude =  loc.getLongitude();

    String Text = "My current location is: " +
    "Latitud = " + loc.getLatitude() +
    "Longitud = " + loc.getLongitude();

    Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
    System.out.println("lat and long "+Text);
  }

  @Override
  public void onProviderDisabled(String provider)
  {
    Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();
  }

  @Override
  public void onProviderEnabled(String provider)
  {
    Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();
  }

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

  }
}

有什么建议可以解决这个问题吗?在此先感谢。

4

0 回答 0