I am using a fragement, I need to get my currently Location (lat and lng) and I need to calculate my currently location with the destination location.
Can you pls give me a hand. what is the best way to calculate the location:
How can I get the distance from my currently location and the destination location using lat and lng ;
LocationManager locationManager;
Location locatio;
locationManager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
String product_latitude = "3.121191";
String product_longtitude = "101.673298";
Double latitude = Double.valueOf(product_latitude);
Double longtitude = Double.valueOf(product_longtitude);
// Calculate the Distance
String product_distance = location.distanceTo(latitude, longtitude);
Try this
You can use static method of Location: distanceBetween to get distance between 2 locations.
doc: here
Use Direction API to find to the distance from your current location to the destination. It returns a JSON object as distance which gives you the distance in mile, you can parse that JSON and display that on your app screen.
For Google's official documentation read here.
And for a tutorial read here.
Hope this would help!!!