Bonjour,
Mon application plante quand je veux récupérer les coordonnées GPS. Voici ma classe:
Merci de votre aide!
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
67
68
69
70
71
72
73 package symplybus.fr; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; public class Geolocaliser { Context mContext; LocationManager locationManager; double[] x; int fini; Geolocaliser(Context mContext){ this.mContext = mContext; } public boolean geolocaliser(double position[]) { fini=2; x=new double[2]; // Acquire a reference to the system Location Manager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. if(location==null) { fini=3; } x[0]=location.getLatitude(); x[1]=location.getLongitude(); fini=0; locationManager.removeUpdates(this); } public void onStatusChanged(String provider, int status, Bundle extras) {} public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { fini=1; } }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); while(fini==2) { if(fini==1 || fini==3) { return false; } else if(fini==0) { position[0]=x[0]; position[1]=x[1]; return true; } } return false; } }
Partager