Previous: http://www.bkjia.com/kf/201208/151127.html
[Java]
Public void getAndRefreshLocation (GeoPoint p ){
Try {
LogUtil. I ("ReviewPositionUI", "Lat =" + p. getLatitudeE6 () + "= Long =" + p. getLongitudeE6 ());
Double lat = (double) p. getLatitudeE6 ()/1000000;
Double lon = (double) p. getLongitudeE6 ()/1000000;
LogUtil. I ("ReviewPositionUI", "Lat =" + lat + "= Long =" + lon );
List <Address> address = mGeocoder. getFromLocation (lat,
Lon, 3 );
If (address! = Null ){
Address addres = address. get (0 );
String addressName = addres. getAdminArea ()
+ Addres. getSubLocality () + addres. getFeatureName ()
+ "Nearby ";
Toast. makeText (mContext, addressName, Toast. LENGTH_LONG). show ();
}
} Catch (AMapException e ){
LogUtil. I ("ReviewPositionUI", e. getMessage ());
}
}
[Java]
Public class GPSLocation {
Private LocationManagerProxy mLocationManager;
Private Context mContext;
LocationManager mManager;
Public GPSLocation (Context context ){
This. mContext = context;
MLocationManager = LocationManagerProxy. getInstance (context );
MManager = (LocationManager) mContext. getSystemService (Context. LOCATION_SERVICE );
}
Public void enableMyLocation (LocationListener listener ){
Location location;
If (NetworkState. TYPE_WIFI = NetworkState. searchNetworkType (mContext )){
Location = mManager. getLastKnownLocation (LocationManager. NETWORK_PROVIDER );
} Else {
Location = mManager. getLastKnownLocation (LocationManager. GPS_PROVIDER );
}
If (location! = Null ){
Listener. onLocationChanged (location );
} Else {
Criteria cri = new Criteria ();
Cri. setAccuracy (Criteria. ACCURACY_COARSE );
Cri. setAltitudeRequired (false );
Cri. setBearingRequired (false );
Cri. setCostAllowed (false );
String bestProvider = mLocationManager. getBestProvider (cri, true );
Try {
MLocationManager. requestLocationUpdates (bestProvider, 2000, 10, listener );
} Catch (Exception e ){
Listener. onLocationChanged (null );
} Www.2cto.com
}
}
Public void disableMyLocation (LocationListener listener ){
If (mLocationManager! = Null ){
MLocationManager. removeUpdates (listener );
MLocationManager. destory ();
MLocationManager = null;
}
If (mManager! = Null ){
MManager. removeUpdates (listener );
}
}
}