Momentan möchte ich den Benutzer aktuelle Position von Breiten- und Längengrad bekommen, aber mein Code kann bekommen, bis ich die Senden-Taste in der Emulator-Einstellung gedrückt habe, aber was ich will, ist automatisch den Standort zu bekommen setze es auf textview, was soll ich tun? Bitte rate mir bitte, dieses Problem zu lösen, da ich den Standortcode nicht kenne.Aktueller Standort nicht automatische Anzeige der Textansicht
Hier ist mein Code
package com.example.rex.ota30;
import android.*;
import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import static com.example.rex.ota30.R.id.textView;
public class Search extends AppCompatActivity implements LocationListener {
private FirebaseDatabase db;
private DatabaseReference sref, lref;
private TextView searchun, searchlo, searchla;
private String un, la, lo;
private LocationManager lm;
private LocationListener ll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
db = FirebaseDatabase.getInstance();
sref = db.getReference("users");
lref = db.getReference("userslocation");
searchun = (TextView) findViewById(R.id.sun);
Intent i = this.getIntent();
un = i.getStringExtra("username");
searchun.setText(un);
searchlo = (TextView) findViewById(R.id.slo);
searchla = (TextView) findViewById(R.id.sla);
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) this);
}
@Override
public void onLocationChanged(Location location) {
la = String.valueOf(location.getLatitude());
searchla.setText(la);
lo = String.valueOf(location.getLongitude());
searchlo.setText(lo);
lref.child(un).child("latitude").setValue(la);
lref.child(un).child("longitude").setValue(lo);
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}
}
Hier ist die Probe der bekommen Lage.
ja in Emulator Sie müssen Breite und Länge erste –
oder überprüft auf reales Gerät einstellen –
Aber ich dachte, der Emulator bereits den Standort bekam? –