curl($url); if (strtoupper($json['status']) == 'OVER_QUERY_LIMIT') { sleep(1); } else if (strtoupper($json['status']) == 'ZERO_RESULTS') { break; } else if (strtoupper($json['status']) == 'OK') { break; } $nc++; } if (isset($json['results']) && isset($json['results'][0]) && isset($json['results'][0]['geometry']) && isset($json['results'][0]['geometry']['location']) && isset($json['results'][0]['geometry']['location']['lat']) && isset($json['results'][0]['geometry']['location']['lng']) ) { return ['address' => $address, 'lat' => $json['results'][0]['geometry']['location']['lat'], 'lng' => $json['results'][0]['geometry']['location']['lng']]; } else { return null; } } /** * @param string $url Contiene la url a buscar. * @return mixed Retorna un array con los datos del json. */ private function curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); $result = curl_exec($ch); return json_decode($result, true); } }