2424 */
2525public class LocationService extends Service {
2626
27- private boolean isSuccess ;
28- private LocationUtils locationUtils ;
27+ private boolean isSuccess ;
2928 private String lastLatitude = "loading..." ;
3029 private String lastLongitude = "loading..." ;
3130 private String latitude = "loading..." ;
@@ -56,9 +55,9 @@ public void onLocationChanged(final Location location) {
5655 if (mOnGetLocationListener != null ) {
5756 mOnGetLocationListener .getLocation (lastLatitude , lastLongitude , latitude , longitude , country , locality , street );
5857 }
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 ));
6261 if (mOnGetLocationListener != null ) {
6362 mOnGetLocationListener .getLocation (lastLatitude , lastLongitude , latitude , longitude , country , locality , street );
6463 }
@@ -73,12 +72,11 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
7372 @ Override
7473 public void onCreate () {
7574 super .onCreate ();
76- locationUtils = new LocationUtils (App .getInstance ());
7775 new Thread (new Runnable () {
7876 @ Override
7977 public void run () {
8078 Looper .prepare ();
81- isSuccess = locationUtils . init ( 1000 , 0 , mOnLocationChangeListener );
79+ isSuccess = LocationUtils . register ( App . getInstance (), 0 , 0 , mOnLocationChangeListener );
8280 if (isSuccess ) ToastUtils .showShortToastSafe (App .getInstance (), "init success" );
8381 Looper .loop ();
8482 }
@@ -99,7 +97,7 @@ public LocationService getService() {
9997
10098 @ Override
10199 public void onDestroy () {
102- locationUtils . removeListener ();
100+ LocationUtils . unregister ();
103101 // 一定要制空,否则内存泄漏
104102 mOnGetLocationListener = null ;
105103 super .onDestroy ();
0 commit comments