Using the Android app, I send the latitude and longitude values ββto the database.
This is my database.

Now on the webpage I need to show the total distance traveled by K.Prathibha.N
I used the Google Maps Direction API to find the distance, but it takes 'id = 2' as the source and 'id = 5' as the destination. But my motto is to find the total distance traveled, that is, id_2 to id_3, to id_4 to id_5.
I use while loop here.
Code snippet:
<?php $params_string=""; $pname = $_POST['name']; //name is passed from a dropdown $query = "SELECT * FROM information WHERE mobile=? ORDER BY id DESC "; $result = $dbConnection->prepare($query); $result->execute(array($pname)); if($result->rowCount() >0) { $params = array(); while($row = $result->fetch()) { $mobile = $row['mobile']; $latitude = $row['latitude']; $cname = $row['name']; $longitude = $row['longitude']; $lat = "17.4136846"; $long = "78.49228289999996"; $params = array("origin" => $latitude.",".$longitude,"destination" => $lat.",".$long,"sensor" => 'true',"units" => 'imperial'); //Join parameters into URL string foreach($params as $var => $val) { $params_string .= '&' . $var . '=' . urlencode($val); } } } // Request URL $url = "http://maps.googleapis.com/maps/api/directions/json?".ltrim($params_string, '&'); // Make our API request $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $return = curl_exec($curl); curl_close($curl); // Parse the JSON response $directions = json_decode($return); // Show the total distance print('<p><strong>Total distance:</strong> ' . ceil(($directions->routes[0]->legs[0]->distance->text)* 1.609344) .' KM'. '</p>'); ?>
Now how to pass destination values ββhere.
My task is to pass the database values ββinto lat and long variables .... Just, for example, I passed the values ββmanually. To get the database values ββat the same time, since the source receives identifier 2, and the receiver receives id 3 values
Example. If he accepts
as id-2, then the destination should be id-3 next
as id-3, then the destination should be id-4, etc.
at the end gives the total distance traveled on that particular day, based on the available geological points.
Fighting this for more than 3 days.
Any suggestions would be helpful.
php google-maps google-direction
Prabs Feb 13 '15 at 5:39 2015-02-13 05:39
source share