public class MapTestActivity
extends Activity implements LocationSource,
AMapLocationListener{
private MapView mapView;
private AMap aMap;
private LocationManagerProxy aMapManager;
private OnLocationChangedListener mListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
mapView =
(MapView)findViewById(R.id.map);
mapView.onCreate(savedInstanceState);
init();
}
private void init() {
// TODO Auto-generated method stub
if(aMap == null){
aMap = mapView.getMap();
}
aMap.setLocationSource(this);
aMap.setMyLocationEnabled(true);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
mapView.onPause();
deactivate();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
mapView.onResume();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@SuppressWarnings("deprecation")
@Override
public void activate(OnLocationChangedListener listener)
{
// TODO Auto-generated method stub
mListener = listener;
if (aMapManager == null) {
aMapManager = LocationManagerProxy.getInstance(this);
// Location API定位采用GPS和网络混合定位方式,时间最短是2000毫秒
aMapManager.requestLocationUpdates(
LocationProviderProxy.AMapNetwork, 2000, 10, this);
}
}
@SuppressWarnings("deprecation")
@Override
public void deactivate() {
// TODO Auto-generated method stub
mListener = null;
if (aMapManager != null) {
aMapManager.removeUpdates(this);
aMapManager.destory();
}
aMapManager = null;
}
@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 Auto-generated method stub
if (mListener != null) {
mListener.onLocationChanged(aLocation);// 显示系统小蓝点
}
}
}