GPS 提供商不是 return 我当前的位置 android

GPS provider not return my current location android

我正在尝试获取用户当前位置,但我的 onLocationChanged 方法从未获得 called.I 在 Manifest.xml 中也添加了权限,但从未调用过 onLocationChange 方法。 我打开了我设备的 GPS,并在两部不同的手机上尝试但无法正常工作。 下面是我的代码 -

public class LocationAwareActivity extends Activity implements
         LocationListener {


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LocationManager locationManager = (LocationManager)
            getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(
    LocationManager.GPS_PROVIDER, 1000, 1, this);

}


@Override
public void onLocationChanged(Location location) {
    Toast.makeText(this, "Current onLocationChanged : "+location.getLatitude()+" , "+location.getLongitude(), Toast.LENGTH_SHORT).show();
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    Toast.makeText(this, "onStatusChanged", Toast.LENGTH_SHORT).show();
}

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

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

以下是manifest.xml-

的代码
 <uses-permission android:name="android.permission.INTERNET"/>
 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

TIA

您获得Google地图密钥了吗? 将它添加到您的项目中。像这样:

<meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Your Google Map Key" />

http://developer.android.com/google/play-services/maps.html

Use the new Fused location provider for fetching the location.

The Fused Location Provider intelligently manages the underlying location technology and gives you the best location according to your needs.

Refer below links:
  1. https://developer.android.com/google/play-services/location.html
  2. http://javapapers.com/android/android-location-fused-provider/
  3. http://www.kpbird.com/2013/06/fused-location-provider-example.html

您没有移动,因此可能无法获得位置更新。
尝试更改此行:

locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 1000, 1, this);

为此:

locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, this);