Not sure if I even approach this correctly, but I need to grab the coordinates from two different addresses stored in a database. I will need to make an array with the two coordinates to use later to calculate the distance between them.
This is my code so far, I’m able to get the coordinates from one of the two addresses only.
$dbQuery = "SELECT CS.cust_address AS sa, CS.cust_city AS sc, CS.cust_state AS ss, CS.cust_zip AS sz, CR.cust_address AS ra, CR.cust_city AS rc, CR.cust_state AS rs, CR.cust_zip AS rz
FROM customers
INNER JOIN customers CS ON (CS.cust_id = ".$shipper.")
INNER JOIN customers CR ON (CR.cust_id = ".$receiver.")
LIMIT 1";
$data = getContent($dbQuery);
foreach($data as $row) {
//Make a variable with the full address, city, state and zipcode.
$shpLocation = $row['sa'] . ' ' . $row['sc'] . ',' . $row['ss'] . ' ' . $row['sz'];
$rcvLocation = $row['ra'] . ' ' . $row['rc'] . ',' . $row['rs'] . ' ' . $row['rz'];
//Get the latitude and longitude of the above address variables
$address =
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$latitude = $output->results[0]->geometry->location->lat;
$longitude = $output->results[0]->geometry->location->lng;
}