php - Calculate road distance between two longitudes and latitudes -


i trying develop android app. have listed places longitude/latitude , other descriptions in backend(php mysql). trying grab users current location , show him road distance listed places descriptions. having difficulty finding road distances form current location other places. guess 1 way using google distance matrix api in case there 2 api calls,

  • 1st 1 device backend.
  • 2nd 1 backend google distance matrix api

and after backend send response device. idea call 2 api purpose. , there other way easily. new development please pardon me if wrong.

thank you.

public float distance(double lat1, double lng1, double lat2, double lng2) {     double earthradius = 6371; // kilometers     double dlat = math.toradians(lat2 - lat1);     double dlng = math.toradians(lng2 - lng1);     double = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.toradians(lat1)) * math.cos(math.toradians(lat2)) * math.sin(dlng / 2)             * math.sin(dlng / 2);     double c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a));     float dist = (float) (earthradius * c);      return dist * 1000; } 

now call in code

float distanceinmeters= distance(oldlatitude, oldlongitude,newlatitude, newlongitude); 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -