Berechnung zwischen zwei Standorten implementiert
This commit is contained in:
parent
a6f02f3936
commit
2ab8f02a43
@ -28,6 +28,8 @@ import com.google.firebase.database.DatabaseError;
|
|||||||
import com.google.firebase.database.DatabaseReference;
|
import com.google.firebase.database.DatabaseReference;
|
||||||
import com.google.firebase.database.FirebaseDatabase;
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
import com.google.firebase.database.ValueEventListener;
|
import com.google.firebase.database.ValueEventListener;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback {
|
public class EarthquakeMapsActivity extends FragmentActivity implements OnMapReadyCallback {
|
||||||
|
|
||||||
@ -42,6 +44,9 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
|
|
||||||
private DatabaseReference mDatenbank;
|
private DatabaseReference mDatenbank;
|
||||||
|
|
||||||
|
Date currentTime;
|
||||||
|
Location currentLocation;
|
||||||
|
|
||||||
private double breitengrad;
|
private double breitengrad;
|
||||||
private double laengengrad;
|
private double laengengrad;
|
||||||
|
|
||||||
@ -50,7 +55,8 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_earthquake_maps);
|
setContentView(R.layout.activity_earthquake_maps);
|
||||||
|
|
||||||
getDataBaseValues(); //TODO Edward: Nur als Anmerkung, diese Methode erfolgt damit deine Methode getDeviceLocation Koordinaten aus der DB bekommt
|
//getDataBaseValues(); //TODO Edward: Nur als Anmerkung, diese Methode erfolgt damit deine Methode getDeviceLocation Koordinaten aus der DB bekommt
|
||||||
|
//TODO Hast schon echt viel erledigt :D Ich habe gedacht das die Class EarthquakeMapsActivity Daten an die DB schickt und die SensorMapsActivity die Daten bekommt, ich glaub die Funktion muss in die andere Class
|
||||||
getLocationPermission();
|
getLocationPermission();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,9 +126,12 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
@Override
|
@Override
|
||||||
public void onComplete(@NonNull Task task) {
|
public void onComplete(@NonNull Task task) {
|
||||||
if (task.isSuccessful()){
|
if (task.isSuccessful()){
|
||||||
Location currentLocation = (Location) task.getResult();
|
currentLocation = (Location) task.getResult();
|
||||||
currentLocation.setLatitude(breitengrad); //TODO Edward: Hier werden beispielweise Koordinaten aus der Datenbank verwendet für Gerät IDG1
|
currentTime = Calendar.getInstance().getTime();
|
||||||
currentLocation.setLongitude(laengengrad);
|
Toast.makeText(EarthquakeMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show();
|
||||||
|
//currentLocation.setLatitude(breitengrad); //Hier werden beispielweise Koordinaten aus der Datenbank verwendet für Gerät IDG1
|
||||||
|
//currentLocation.setLongitude(laengengrad); //Hier werden beispielweise Koordinaten aus der Datenbank verwendet für Gerät IDG1
|
||||||
|
//setDataBaseValues(); //TODO Aron: Sobald ich die Funktion aufrufen will crashed die APP
|
||||||
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
|
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@ -141,6 +150,8 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
|
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void getDataBaseValues()
|
public void getDataBaseValues()
|
||||||
{
|
{
|
||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
@ -178,9 +189,9 @@ public class EarthquakeMapsActivity extends FragmentActivity implements OnMapRea
|
|||||||
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
mDatenbank = FirebaseDatabase.getInstance().getReference();
|
||||||
mDatenbank.child("overview").child("IDG1").child("ip").setValue("10.00.00.001");
|
mDatenbank.child("overview").child("IDG1").child("ip").setValue("10.00.00.001");
|
||||||
mDatenbank.child("overview").child("IDG1").child("vibration").setValue(true);
|
mDatenbank.child("overview").child("IDG1").child("vibration").setValue(true);
|
||||||
mDatenbank.child("overview").child("IDG1").child("timestamp").setValue(1113456789);
|
mDatenbank.child("overview").child("IDG1").child("timestamp").setValue(currentTime.toString()); //aktueller Zeitstempel wird in Datenbank eingetragen
|
||||||
mDatenbank.child("overview").child("IDG1").child("breitengrad").setValue(49.5);
|
mDatenbank.child("overview").child("IDG1").child("breitengrad").setValue(currentLocation.getLatitude()); //aktueller Breitengrad
|
||||||
mDatenbank.child("overview").child("IDG1").child("laengengrad").setValue(11.5);
|
mDatenbank.child("overview").child("IDG1").child("laengengrad").setValue(currentLocation.getLongitude()); //aktueller Längergrad
|
||||||
mDatenbank.child("overview").child("IDG1").child("amplitude").setValue(1001);
|
mDatenbank.child("overview").child("IDG1").child("amplitude").setValue(1001);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,31 +1,55 @@
|
|||||||
package de.edotzlaff.schockwelle;
|
package de.edotzlaff.schockwelle;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import android.Manifest;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
|
import com.google.android.gms.location.FusedLocationProviderClient;
|
||||||
|
import com.google.android.gms.location.LocationServices;
|
||||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||||
import com.google.android.gms.maps.GoogleMap;
|
import com.google.android.gms.maps.GoogleMap;
|
||||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||||
import com.google.android.gms.maps.SupportMapFragment;
|
import com.google.android.gms.maps.SupportMapFragment;
|
||||||
import com.google.android.gms.maps.model.LatLng;
|
import com.google.android.gms.maps.model.LatLng;
|
||||||
import com.google.android.gms.maps.model.MarkerOptions;
|
import com.google.android.gms.maps.model.MarkerOptions;
|
||||||
|
import com.google.android.gms.tasks.OnCompleteListener;
|
||||||
|
import com.google.android.gms.tasks.Task;
|
||||||
import com.google.firebase.database.DataSnapshot;
|
import com.google.firebase.database.DataSnapshot;
|
||||||
import com.google.firebase.database.DatabaseError;
|
import com.google.firebase.database.DatabaseError;
|
||||||
import com.google.firebase.database.DatabaseReference;
|
import com.google.firebase.database.DatabaseReference;
|
||||||
import com.google.firebase.database.FirebaseDatabase;
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
import com.google.firebase.database.ValueEventListener;
|
import com.google.firebase.database.ValueEventListener;
|
||||||
|
|
||||||
import org.w3c.dom.Text;
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCallback {
|
public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCallback {
|
||||||
|
|
||||||
|
|
||||||
|
private static final String TAG = "MainActivity";
|
||||||
|
private static final String FINE_LOCATION = Manifest.permission.ACCESS_FINE_LOCATION;
|
||||||
|
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1234;
|
||||||
|
|
||||||
|
//vars
|
||||||
|
private Boolean mLocationPermissionsGranted = false;
|
||||||
private GoogleMap mMap;
|
private GoogleMap mMap;
|
||||||
|
private FusedLocationProviderClient mFusedLocationProviderClient;
|
||||||
|
|
||||||
|
Date currentTime;
|
||||||
|
Location currentLocation;
|
||||||
|
|
||||||
|
private double breitengrad;
|
||||||
|
private double laengengrad;
|
||||||
|
|
||||||
private DatabaseReference mDatenbank;
|
private DatabaseReference mDatenbank;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -35,7 +59,39 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
|
|
||||||
TextView tv= (TextView) findViewById(R.id.txtSensor);
|
TextView tv= (TextView) findViewById(R.id.txtSensor);
|
||||||
|
|
||||||
initMap();
|
getLocationPermission(); //Zuerst werden die aktuellen Standortdaten ermittelt
|
||||||
|
|
||||||
|
//getDataBaseValues(); // Hier werden die Daten von der DB abgefragt //TODO Aron: sobald die Methode aufgerufen wird crashed die APP
|
||||||
|
|
||||||
|
//distance(currentLocation.getLatitude(), currentLocation.getLongitude(),breitengrad,laengengrad); //Übergabe zur Berechnung der Distanz zwischen Auslöser und aktuellem Standort
|
||||||
|
|
||||||
|
//TODO Patrick: die Funktion distance gibt Meter zurück, könntest Du das mit dem Zeitstempel und der Berechnung bis zur Vibration machen?
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getLocationPermission() {
|
||||||
|
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION};
|
||||||
|
if (ContextCompat.checkSelfPermission(this.getApplicationContext(), FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
mLocationPermissionsGranted = true;
|
||||||
|
initMap();
|
||||||
|
} else {
|
||||||
|
ActivityCompat.requestPermissions(this, permissions, LOCATION_PERMISSION_REQUEST_CODE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||||
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
|
mLocationPermissionsGranted = false;
|
||||||
|
|
||||||
|
switch (requestCode) {
|
||||||
|
case LOCATION_PERMISSION_REQUEST_CODE: {
|
||||||
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
mLocationPermissionsGranted = true;
|
||||||
|
//initalize or map
|
||||||
|
initMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void initMap(){
|
void initMap(){
|
||||||
@ -47,14 +103,60 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMapReady(GoogleMap googleMap) {
|
public void onMapReady(GoogleMap googleMap) {
|
||||||
|
|
||||||
|
Toast.makeText(this, "Map is ready", Toast.LENGTH_SHORT).show();
|
||||||
mMap = googleMap;
|
mMap = googleMap;
|
||||||
|
|
||||||
|
if (mLocationPermissionsGranted) {
|
||||||
|
getDeviceLocation();
|
||||||
|
|
||||||
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
|
||||||
|
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mMap.setMyLocationEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
// Add a marker in Sydney and move the camera
|
// Add a marker in Sydney and move the camera
|
||||||
LatLng sydney = new LatLng(-34, 151);
|
LatLng sydney = new LatLng(-34, 151);
|
||||||
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
|
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
|
||||||
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
|
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void getDeviceLocation(){
|
||||||
|
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
|
||||||
|
try {
|
||||||
|
if (mLocationPermissionsGranted){
|
||||||
|
final Task location = mFusedLocationProviderClient.getLastLocation();
|
||||||
|
|
||||||
|
location.addOnCompleteListener(new OnCompleteListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onComplete(@NonNull Task task) {
|
||||||
|
if (task.isSuccessful()){
|
||||||
|
currentLocation = (Location) task.getResult();
|
||||||
|
currentTime = Calendar.getInstance().getTime();
|
||||||
|
Toast.makeText(SensorMapsActivity.this, currentTime.toString(), Toast.LENGTH_SHORT).show();
|
||||||
|
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),15f);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
Toast.makeText(SensorMapsActivity.this, "Current Location unavailable", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}catch (SecurityException e){
|
||||||
|
Log.e(TAG,"Device Location not found" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveCamera(LatLng latlng, float zoom){
|
||||||
|
Log.d(TAG,"Latitude: "+latlng.latitude+"Longitude: "+latlng.longitude);
|
||||||
|
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, zoom));
|
||||||
|
}
|
||||||
|
|
||||||
//TODO Edward: Mit Methode getDataBaseValues werden die Werte in der DB abgefragt. In Methode processDataBaseValues werden diese beispielhaft ausgelesen. Kann nach Bedarf angepasst werden.
|
//TODO Edward: Mit Methode getDataBaseValues werden die Werte in der DB abgefragt. In Methode processDataBaseValues werden diese beispielhaft ausgelesen. Kann nach Bedarf angepasst werden.
|
||||||
public void getDataBaseValues()
|
public void getDataBaseValues()
|
||||||
{
|
{
|
||||||
@ -119,16 +221,15 @@ public class SensorMapsActivity extends FragmentActivity implements OnMapReadyCa
|
|||||||
Log.w("Datenbankfehler", error.toException());
|
Log.w("Datenbankfehler", error.toException());
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Edward Distanz zwischen zwei Punkten berechnen
|
|
||||||
//TODO Edward Dauer für Timer berechnen bis Smartphone vibriert
|
//TODO Edward Dauer für Timer berechnen bis Smartphone vibriert
|
||||||
/*
|
|
||||||
private float distance(double currentlatitude, double currentlongitude, double originLat, double originLon) {
|
private float distance(double currentlatitude, double currentlongitude, double originLat, double originLon) {
|
||||||
|
|
||||||
float[] results = new float[1];
|
float[] results = new float[1];
|
||||||
Location.distanceBetween(currentlatitude, currentlongitude, -34, 151, results);
|
Location.distanceBetween(currentlatitude, currentlongitude, originLat, originLon, results);
|
||||||
float distanceInMeters = results[0];
|
float distanceInMeters = results[0];
|
||||||
|
|
||||||
return distanceInMeters;
|
return distanceInMeters;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user