位置情報の保存の仕方についての質問
Android Studioで使用した位置情報を更新した際の経度と緯度が表示されるアプリを作っているのですが、更新前の位置情報を保存したいのですがどのようにすればいいか悩んでおり、質問しました。Javaを使用してます。
下のソースコードは位置情報が更新した際に緯度と経度が出るものです。
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
LocationManager lm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
setUpMap();
}
public void setUpMap(){
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60 * 15 * 1000, 50, new SampleLocationListener());
mMap.setMyLocationEnabled(true);
}
class SampleLocationListener implements LocationListener {
public void onLocationChanged(Location lc){
double lt = lc.getLatitude();
double ln = lc.getLongitude();
LatLng ltn = new LatLng(lt, ln);
mMap.moveCamera(CameraUpdateFactory.newLatLng(ltn));
mMap.moveCamera(CameraUpdateFactory.zoomTo(17));
Toast.makeText(getBaseContext(), "現在地は\n緯度:" + lt + "経度" + ln + "です", Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String pv){}
public void onProviderEnabled(String pv){}
public void onStatusChanged(String pv,int status,Bundle ex){}
}