ユーザーの場所(ドライバーまたは移動場所)と固定緯度経度の間の距離を計算しようとしています。ただし、テキストには結果が表示されず、TextViewのみが表示されます。
そして、ユーザーが固定緯度経度の特定の半径に到達するたびに、imageviewは別のドローアブルに変更されます。私はこれを1週間以上試みています。助けてくれる人はいますか?
メインコード:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lights);
//placing location
LocationManager loc = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Location location = loc.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double clong = location.getLongitude();
double clat = location.getLatitude(); //current longitude and latitude
double latitude=0.305085;
double longitude=101.70506; //fixed location
double dist = Math.sqrt(Math.pow((111.3 * (latitude - clat)),2) + Math.pow((71.5 * (longitude - clong)),2)) * 1000;
if(dist<1000){
calculate(dist);
tvDis = (TextView)findViewById(R.id.distance);
tvDis.setText(dist+"m");
}
}
public void calculate(double x){
ImageView light = (ImageView)findViewById(R.id.imageView1);
if (x<1000){
light.setImageResource(R.drawable.icon_yellow);
if(x<500){
light.setImageResource(R.drawable.icon_red);
}
}
else{
light.setImageResource(R.drawable.icon_green);
}
}
1000をもっと大きな数に変えてみましたが、それでも運がありません。