1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.example.eketha.PaddyArea;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.example.eketha.FertilizerGuidence;
import com.example.eketha.R;
public class PaddyAreaResult extends AppCompatActivity {
Button btLocation,nxt1,navigateFertiGuidence;
TextView area,d1,d2;
private String distance1,lon4,lat4,lon3,lat3;
private int distance;
private double lol,loll,lol1,loll1;
private String fertilizerType;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paddy_area_result);
distance1 = getIntent().getStringExtra("distance1");
lat3 = getIntent().getStringExtra("lat3");
lon3 = getIntent().getStringExtra("lon3");
lat4 = getIntent().getStringExtra("lat4");
lon4 = getIntent().getStringExtra("lon4");
fertilizerType = getIntent().getStringExtra("fertilizerType");
navigateFertiGuidence = findViewById(R.id.navigateFertiGuidence);
area = findViewById(R.id.area);
// d1 = findViewById(R.id.d1);
// d2 = findViewById(R.id.d2);
// d1.setText(distance1);
int x = Integer.valueOf(distance1);
lol = Double.valueOf(lat3);
loll = Double.valueOf(lon3);
lol1 = Double.valueOf(lat4);
loll1 = Double.valueOf(lon4);
distance = calculateDistanceInKilometer(lol,loll,lol1,loll1);
// distance = calculateDistanceInKilometer(6.713408110319169,79.91602709961393,6.713184955531217,79.91592511089544);
int a = distance * x;
int hect = a / 10000;
// d2.setText(String.valueOf(distance));
area.setText(String.valueOf(a) + "m");
navigateFertiGuidence.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(PaddyAreaResult.this, FertilizerGuidence.class);
intent.putExtra("fertilizerType",fertilizerType);
intent.putExtra("areaResult",String.valueOf(hect));
startActivity(intent);
}
});
}
public final static double AVERAGE_RADIUS_OF_EARTH_KM = 6371;
public int calculateDistanceInKilometer(double userLat, double userLng,
double venueLat, double venueLng) {
double latDistance = Math.toRadians(userLat - venueLat);
double lngDistance = Math.toRadians(userLng - venueLng);
double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
+ Math.cos(Math.toRadians(userLat)) * Math.cos(Math.toRadians(venueLat))
* Math.sin(lngDistance / 2) * Math.sin(lngDistance / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double r = (AVERAGE_RADIUS_OF_EARTH_KM * c) * 1000;
int x = (int) r * 1;
return x;
}
}