I am trying to find distance between two locations in android using the LocationListener and related classes and methods.
- I was able to get the coordinates of the given address by using geo coding class. And also was able to get distance between two addresses using the distanceto method.
2.Now I want to give address and get coordinates and then get the distance between previous given address location and the current location (which changes) in real time. since there is no current location method in android i got to use Location Listener.
- the want the distance between the given address location coordinate and the real time changing location when moving using locationlistener and other location classes and methods. I wrote and deployed on a device with all permissions in manifest, but the gps gets disabled as soon as i start the app. Below is my code
//below code to get the address location coordinates which is succesful
int i=1;
Geocoder geo=new Geocoder(this);
List<Address> addressList = geo.getFromLocationName(adrs,i);
Address address = addressList.get(0);
if(address.hasLatitude() && address.hasLongitude()){
lat = address.getLatitude();
lon = address.getLongitude();
String adlalo= "Latitude of above address: "+lat +" " +
" "+"Longitude of above address: "+lon;
t2.setText(adlalo);
}
// and below is the location listener class
public class LoctListner implements LocationListener
{
public void onLocationChanged(Location loc)
{
t3 = (TextView) findViewById(R.id.textView3);
l1.setLatitude(lat);
l1.setLongitude(lon);
float d=l1.distanceTo(loc);
String s="the distance between starting and ending point is "+d;
t3.setText(s);
}
}
help me where i made the mistake. Unable to see the log since i got to take the device out to test.since this app needs a moving location.Thanks in advance