mardi 26 juin 2018

compare driving distance from JSON array

I'm using googledistancematrix api for calculating distance from login user to all my fields of db. That's my controller code.

$field_list = Field::all();
for ($i=0; $i < count($field_list); $i++)
    { 
        $destination = $field_list[$i]['latitude'] . "," . $field_list[$i]['longitude'];
        $details = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=$origin&destinations=$destination&mode=driving&sensor=false";
        $json = file_get_contents($details);
        $details = json_decode($json, TRUE);
        if (count($details['destination_addresses']) > 0 )
        {
            $distance = $details['rows'][0]['elements'][0]['duration']['text'];
            $field_list[$i]->distance = $distance;
        }
    }

By this i'm getting following response:

https://jsoneditoronline.org/?id=a35cedef327244ceb19ed35a2a4c8ddf

But i want to show only those fields whose distance < or = 30 mins. Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire