Android – how to find distance using google places api

android

I am developing an app using Google pLaces api. i am able to get the list of cafe that are near a user who is using my app. the resultant list includes details of places such as the name of the place, its address, latitude longitude values and phone number.
What i want to know is how do i request place api to return the distance between the user and each of the entry in the result list.
i have gone through few links posted on stackoverflow that discuss a similar topic. i went through Googles documentation as well, but it does not mention anything about getting these distances. i want to refrain myself from using any mathematical formula like great circle algorithm because in that case the distance returned will be straight line distance and that will not be an accurate estimation of distance.
so can anybody please tell me how do request places api to give me the distance between the user and every entry in the result?

few of the links that i went through are:
How do i find distance between one place to another using Geolocation or Similiar API without embedding a Google Map?

find Distance in kilometers in Android using google places Api

How to get Distance Kilometer in android?

Best Answer

I Think As you said- you want to refrain yourself from using

any mathematical formula so you can Also try this-

You can get distance from address of location

http://maps.googleapis.com/maps/api/distancematrix/xml?origins="+a+"&destinations="+b+"&mode=driving&language=en-EN&sensor=false with a=addressFrom, b=addressTo

If you have lat,long of location, you can get address of that location as:

 double latiTude = 10.3929393;
 double longiTude = 150.93984884;

 Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
  GeoPoint p= new GeoPoint((int) (latiTude * 1E6), (int) (longiTude * 1E6));
  List<Address> address = geocoder.getFromLocation(
                                                    p.getLatitudeE6() / 1E6,
                                                    p.getLongitudeE6() / 1E6, 1);
    if (address.size() > 0) 
    {
    String addressFroLatLong= "";
    for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++) 
    {   addressFroLatLong+= address.get(0).getAddressLine(i) + "\n";
    }   
   }

PLease upvote if helped. nothing else. Thanks, happy to help enjoy..

Related Topic