0
私は現在のロケーションの緯度と経度を別の緯度と経度と比較したいと考えています。 私のコードはエラーがなく、私の場所はここに与えられた緯度と経度ロケーションマネージャーロケーションの取得と比較
を通過したときに何も起こりません私のコードです:
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
mMap.setMyLocationEnabled(true);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION);
}
}
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//Criteria criteria = new Criteria();
Context context=getApplication();
String text="WRONG DIRECTION";
int duration=Toast.LENGTH_SHORT;
//String provider = lm.getBestProvider(criteria, false);
Location location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
Toast toast=Toast.makeText(context, text, duration);
double c = location.getLatitude();
double d = location.getLongitude();
if(c==31.271397&&d==29.999595){
toast.show();
}
else{
toast.cancel();
}
を比較するdistanceto機能を使用することができ、マップが機能していますが、私の場所が通過する時に与えられた緯度と長い何も起こりません。 –
更新された回答を確認できます。また、場所が別の場所と等しいかどうかを確認することはできません。あなたは近接性をチェックし、それに基づいて計算を行うことができます。 –