public function getGoogleCoords($city) { $city_db = City::whereName($city)->first(); $google_api = "AIzaSyB-7u1CvRIkmsjcHVVQgilPj6doeIh93oA"; $baseURL = "http://maps.googleapis.com/maps/api/geocode/json?address="; $format = "&key=" . $google_api; $query = "philippines,+" . $city_db->province->name . ",+" . $city_db->name; $callURL = $baseURL . $query . $format; $session = curl_init($callURL); curl_setopt($session, CURLOPT_URL, $callURL); curl_setopt($session, CURLOPT_BINARYTRANSFER, true); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $json = curl_exec($session); curl_close($session); // Decode JSON response: $coords = json_decode($json, true); dd($coords); $data['lat'] = $coords["results"][0]["geometry"]["location"]["lat"]; $data['long'] = $coords["results"][0]["geometry"]["location"]["long"]; $data['postcode'] = $coords["results"][0]["address_components"]; $data['city_id'] = $city_db->id; dd($data); return $data; }