public class LocationInfoManeger implements
AMapLocationListener {
private LocationInfo mLocation;
private static LocationInfoImp mLocationInfoImp;
private static LocationInfoManeger instance;
private static LocationManagerProxy mAMapLocManager =
null;
public static LocationInfoManeger getInstance() {
if (instance == null) {
instance = new LocationInfoManeger();
}
return instance;
}
public void setLocationInfoLisener(LocationInfoImp lisener)
{
instance.mLocationInfoImp = lisener;
}
public void activeLocate() {
if (mAMapLocManager == null) {
new
Handler(TripApplication.getContext().getMainLooper()).post(new
Runnable() {
@Override
public void run() {
mAMapLocManager = LocationManagerProxy
.getInstance(TripApplication.getContext());
mAMapLocManager.requestLocationUpdates(
LocationProviderProxy.AMapNetwork, 5000L, 10F,
LocationInfoManeger.this);
}
});
}
}
public void deactiveLocate() {
if (mAMapLocManager != null) {
mAMapLocManager.removeUpdates(this);
}
}
public LocationInfo getmLocationInfoModel() {
return instance.mLocation;
}
@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String arg0, int arg1, Bundle
arg2) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(AMapLocation aLocation) {
// TODO 高德定位接口回调成功
// 将高德模型转化为阿里的位置模型
if (aLocation != null) {
mLocation = new LocationInfo();
mLocation.setLongtitude(aLocation.getLongitude());
mLocation.setLatitude(aLocation.getLatitude());
mLocation.setProvince(aLocation.getProvince());
String cityName =
Utils.formatterCityName(aLocation.getCity());
mLocation.setCity(cityName);
mLocation.setDistrict(aLocation.getDistrict());
mLocation.setProvider(aLocation.getProvider());
String cityCode =
Utils.getCityCodeByCityName(aLocation.getCity());
mLocation.setCityCode(cityCode);
}
Log.d(Utils.LOGTAG,
" LocationCallback location changed ==" +
mLocation.toString());
mLocationInfoImp.onLocationInfoChanged(mLocation);
}