Skip to content

Instantly share code, notes, and snippets.

@rest-full
Created November 27, 2022 21:56
Show Gist options
  • Save rest-full/96d917b3d70b784e3b140b9f816ef2fe to your computer and use it in GitHub Desktop.
Save rest-full/96d917b3d70b784e3b140b9f816ef2fe to your computer and use it in GitHub Desktop.
curl api google map
echo searching(['CURLOPT_CUSTOMREQUEST' => 'POST', 'CURLOPT_FOLLOWLOCATION' => true, 'CURLOPT_HTTPGET' => true, 'CURL_SSL_VERIFYPPER' => 0, 'CURL_HEADER' => 0]);
function searching(array $datas):string
{
$ch = curl_init('https:\\maps.googleapis.com\maps\api\geocode\json?key=meu_key&address=Rua+Atílio+Milano,+171+-+Del+Castilho,+Rio+de+Janeiro+-+RJ,+21050-560');
if (array_key_exists('CURLOPT_CUSTOMREQUEST', $datas) !== false) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $datas['CURLOPT_CUSTOMREQUEST']);
}
if (array_key_exists('CURLOPT_POSTFIELDS', $datas) !== false) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $datas['CURLOPT_POSTFIELDS']);
}
if (array_key_exists('CURLOPT_FOLLOWLOCATION', $datas) !== false) {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $datas['CURLOPT_FOLLOWLOCATION']);
}
if (array_key_exists('CURLOPT_SSL_VERIFYPEER', $datas) !== false) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $datas['CURLOPT_SSL_VERIFYPEER']);
}
if (array_key_exists('CURLOPT_ENCODING', $datas) !== false) {
curl_setopt($ch, CURLOPT_ENCODING, $datas['CURLOPT_ENCODING']);
}
if (array_key_exists('CURLOPT_CONNECTTIMEOUT', $datas) !== false) {
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $datas['CURLOPT_CONNECTTIMEOUT']);
}
if (array_key_exists('CURLOPT_USERAGENT', $datas) !== false) {
curl_setopt($ch, CURLOPT_USERAGENT, $datas['CURLOPT_USERAGENT']);
}
if (array_key_exists('CURLOPT_HEADER', $datas) !== false) {
curl_setopt($ch, CURLOPT_HEADER, $datas['CURLOPT_HEADER']);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if ($response === false) {
throw new Exceptions(curl_error($ch));
}
$response = $response;
curl_close($ch);
return $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment