Reputation: 4696
I am trying to get user current location but my onLocationChanged method never get called.I have added permissions in Manifest.xml also,But onLocationChange method never get called. I have open GPS of my device and try it on two different mobile but not working. Below is my code -
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();
}
and below is code of 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
Upvotes: 3
Views: 4937
Reputation: 225
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:
Upvotes: 0
Reputation: 3620
You might not get location updates since you do not move.
Try changing this line:
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 1000, 1, this);
To this:
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 0, this);
Upvotes: 0
Reputation: 127
Did you obtain Google Map Key? add it on your project. like this:
<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
Upvotes: 1