0
我已經做到了,所以它輸出的Lat & Lng當我在手機上全新安裝APK時,它會將它寫入5次,但在此之後,工作......我如何才能使其工作?無法讓android一直輸出Lat&Lng到Textview
在日誌中,它輸出我按下按鈕,但似乎沒有做任何事情。我測試的設備是銀河邊緣S7運行Android 7
下面的代碼
getLocation = (LocationManager) getSystemService(LOCATION_SERVICE);
listenLocation = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
townName.append(location.getLatitude() + " " + location.getLongitude());
}
@Override
public void onProviderDisabled(String provider) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
};
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{
android.Manifest.permission.ACCESS_FINE_LOCATION,android.Manifest.permission.ACCESS_COARSE_LOCATION,
android.Manifest.permission.INTERNET
}, 10);
return;
}
}else{
configureButton();
}
}
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
switch(requestCode){
case 10:
if (grantResults.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
configureButton();
return;
}
}
private void configureButton() {
location.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
getLocation.requestLocationUpdates("gps", 5000, 0, listenLocation);
}
});
}
使用'FusedLocationProviderAPI'用' GPSChecker' – Piyush