我的应用会在当前位置显示标记。 GPS设置警报对话框将显示GPS是否已禁用。启用GPS并返回应用程序后,地图无法刷新。所以我必须强行停止我的应用并再次打开。如何刷新地图活动?
GoogleMap googleMap;
GPSTracker gps;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
ViewMap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void ViewMap() {
if(googleMap == null) {
SupportMapFragment supportMapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.googleMap);
googleMap = supportMapFragment.getMap();
gps = new GPSTracker(MainActivity.this);
if(gps.canGetLocation()) {
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
LatLng latLng = new LatLng(latitude,longitude);
TextView locationTv = (TextView) findViewById(R.id.latlongLocation);
googleMap.addMarker(new MarkerOptions().position(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
locationTv.setText("Latitude:" + latitude + ", Longitude:" + longitude);
}
else {
gps.showSettingsAlert();
}
}
}
@Override
protected void onResume() {
super.onResume();
ViewMap();
}