0
我正在開發android應用程序,它會告知用戶他(哪個樓)在哪裏,gps工作正常,但它不準確,爲什麼我在我的代碼中使用範圍,因爲建築物非常靠近彼此之間,但在34樓使用許多IF ELSE是沒有效率的。 還有其他方法嗎?android gps座標比較
這是我的代碼。 package com.example.gps;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity {
Button btnShowLocation;
// GPSTracker class
GPSTracker gps,gps2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnShowLocation = (Button) findViewById(R.id.btnShowLocation);
// show location button click event
btnShowLocation.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// create class object
gps = new GPSTracker(MainActivity.this);
// check if GPS enabled
if(gps.canGetLocation()){
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
if((latitude >=21.4886 && latitude <=21.4893)&& (longitude >=39.2454 && longitude <=39.2459))
// \n is for new line
//Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
Toast.makeText(getApplicationContext(), "Your are in building 7 " , Toast.LENGTH_LONG).show();
else
if((latitude >=21.48899 && latitude <=21.4899)&& (longitude >=39.2456 && longitude <=39.2459))
Toast.makeText(getApplicationContext(), "Your are in building 8 " , Toast.LENGTH_LONG).show();
//}
}else{
// can't get location
// GPS or Network is not enabled
// Ask user to enable GPS/network in settings
gps.showSettingsAlert();
}
}
});
}
}