Reputation: 1622
I' m developing an app that use the google maps api
, now it worked fine into my real device which i used to the test the app.Few days ago i made an hard reset on my tablet and when i tried to test my app again, it didn't work as before.so in my logcat i see that the locationClient
is connected, but it can't recognize my position, so onLocationChanged
is never called.
i notice this into my logcat:
I/Google Maps Android API(2924): Google Play services client version: 5089000
I/Google Maps Android API(2924): Google Play services package version: 5089032
i know that these are two different versions of google play services, i can't understand how to fix it, because before tablet's hard reset,i hadn't got this info into logcat.
this is my manifest.xml:
?xml version="1.0" encoding="utf-8"?>
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.logic.main"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<permission
android:name="com.logic.main.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.logic.main.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.MyAppTheme" >
<activity
android:name="com.logic.main.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.logic.maps.activity.MapsActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name" >
</activity>
<service
android:name="com.logic.maps.backgroundService.LocationBackgroundService"
android:enabled="true" >
</service>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="MyApiKey" />
</application>
</manifest>
activity:
public class MapsActivity extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener,
LocationListener, OnInfoWindowClickListener, OnMarkerClickListener {
private static final long UPDATE_INTERVAL = 5000;
private static final long FASTEST_INTERVAL = 1000;
private GoogleMap map = null;
private LocationClient locationClient;
private Location myLocation;
private LocationRequest locationRequest;
private LatLng newPosition;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
locationClient = new LocationClient(this, this, this);
locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(UPDATE_INTERVAL)
.setFastestInterval(FASTEST_INTERVAL).setSmallestDisplacement(10);
if (locationClient != null)
// connect the client to the Google Play services
locationClient.connect();
}
@Override
public void onLocationChanged(Location location) {
//THIS IS NEVER CALLED
newPosition = new LatLng(location.getLatitude(), location.getLongitude());
myLocation = location;
map.animateCamera(CameraUpdateFactory.newLatLngZoom(newPosition, 15));
}
@Override
public void onConnected(Bundle arg0) {
//*************************** AT THE BEGINNING THIS IS CALLED***************/
// BUT onLocationChanged is never called
Toast.makeText(this, "I'm bringing you to your area.", Toast.LENGTH_SHORT).show();
locationClient.requestLocationUpdates(locationRequest, this);
}
@Override
public void onDisconnected() {
Toast.makeText(this, "Disconnected. Please re-connect.", Toast.LENGTH_SHORT).show();
}
[...]
}
thanks for any help.
Upvotes: 0
Views: 877
Reputation: 12181
Enable location services:
settings->location and security->under my location-> select use wireless and use gps.
Upvotes: 1
Reputation: 4148
Install the latest Google Play Services from the Android SDK manager
Upvotes: 1
Reputation: 728
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
// Creating a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Getting the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
// Getting Current Location
locationManager.requestLocationUpdates(provider, 10000L, 1f, (LocationListener) this);
Upvotes: 0