24
24
*/
25
25
public class LocationService extends Service {
26
26
27
- private boolean isSuccess ;
28
- private LocationUtils locationUtils ;
27
+ private boolean isSuccess ;
29
28
private String lastLatitude = "loading..." ;
30
29
private String lastLongitude = "loading..." ;
31
30
private String latitude = "loading..." ;
@@ -56,9 +55,9 @@ public void onLocationChanged(final Location location) {
56
55
if (mOnGetLocationListener != null ) {
57
56
mOnGetLocationListener .getLocation (lastLatitude , lastLongitude , latitude , longitude , country , locality , street );
58
57
}
59
- country = locationUtils .getCountryName (Double .parseDouble (latitude ), Double .parseDouble (longitude ));
60
- locality = locationUtils .getLocality (Double .parseDouble (latitude ), Double .parseDouble (longitude ));
61
- street = locationUtils .getStreet (Double .parseDouble (latitude ), Double .parseDouble (longitude ));
58
+ country = LocationUtils .getCountryName (App . getInstance (), Double .parseDouble (latitude ), Double .parseDouble (longitude ));
59
+ locality = LocationUtils .getLocality (App . getInstance (), Double .parseDouble (latitude ), Double .parseDouble (longitude ));
60
+ street = LocationUtils .getStreet (App . getInstance (), Double .parseDouble (latitude ), Double .parseDouble (longitude ));
62
61
if (mOnGetLocationListener != null ) {
63
62
mOnGetLocationListener .getLocation (lastLatitude , lastLongitude , latitude , longitude , country , locality , street );
64
63
}
@@ -73,12 +72,11 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
73
72
@ Override
74
73
public void onCreate () {
75
74
super .onCreate ();
76
- locationUtils = new LocationUtils (App .getInstance ());
77
75
new Thread (new Runnable () {
78
76
@ Override
79
77
public void run () {
80
78
Looper .prepare ();
81
- isSuccess = locationUtils . init ( 1000 , 0 , mOnLocationChangeListener );
79
+ isSuccess = LocationUtils . register ( App . getInstance (), 0 , 0 , mOnLocationChangeListener );
82
80
if (isSuccess ) ToastUtils .showShortToastSafe (App .getInstance (), "init success" );
83
81
Looper .loop ();
84
82
}
@@ -99,7 +97,7 @@ public LocationService getService() {
99
97
100
98
@ Override
101
99
public void onDestroy () {
102
- locationUtils . removeListener ();
100
+ LocationUtils . unregister ();
103
101
// 一定要制空,否则内存泄漏
104
102
mOnGetLocationListener = null ;
105
103
super .onDestroy ();
0 commit comments