Bonjour à tous,
J'ai un problème de précision du GPS dans une application que je suis entrain de développer.
Quand je demande ma position, j'obtiens une location qui est à plus 50 m (des fois ça part jusqu'à 1km).
Par contre quand j'utilise l'application android googlemap la précision est beaucoup mieux .
Voici un extrait de mon code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 googleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build();Je me demande s'il n'y a pas un paramètre que j'ai raté ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 @Override protected void onStart() { if(googleApiClient!=null) googleApiClient.connect(); super.onStart(); } @Override protected void onStop() { if(googleApiClient!=null) googleApiClient.disconnect(); super.onStop(); } @Override protected void onPause() { //Unregister for location callbacks: if (googleApiClient != null && googleApiClient.isConnected()) { LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this); } super.onPause(); } @Override public void onConnected(@Nullable Bundle bundle) { //getCurrentLocation(); Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation( googleApiClient); if (mLastLocation != null) { //place marker at current position mGoogleMap.clear(); latLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude()); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(latLng); markerOptions.title("Position Actuelle"); markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); // markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.blue_dot)); mCurrLocation = mGoogleMap.addMarker(markerOptions); mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, CAMERA_ZOOM)); } mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(5000); //5 seconds mLocationRequest.setFastestInterval(3000); //3 seconds mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); //mLocationRequest.setSmallestDisplacement(0.1F); //1/10 meter LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, mLocationRequest, this); } @Override public void onLocationChanged(Location location) { //remove previous current location marker and add new one at current position if (mCurrLocation != null) { mCurrLocation.remove(); } latLng = new LatLng(location.getLatitude(), location.getLongitude()); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(latLng); markerOptions.title(getString(R.string.current_position)); markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)); mCurrLocation = mGoogleMap.addMarker(markerOptions); }
Merci à tous.
Partager