Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save LucianoCharlesdeSouza/f3d67491a92c5004209819065137ad55 to your computer and use it in GitHub Desktop.
Save LucianoCharlesdeSouza/f3d67491a92c5004209819065137ad55 to your computer and use it in GitHub Desktop.
<?php
function httpGet(string $url, array $headers = [])
{
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER =>$headers,
));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$apiKey = 'your-api-key';
//EndPoint para pesquisar passando o endereço
$url = 'https://geocoder.ls.hereapi.com/6.2/geocode.json?';
//Parametros para compor a requisição
$paramns = ['searchtext' => 'Centro Gaspar SC Brasil', 'gen' => 9, 'apiKey' => $apiKey];
//Montamos a url formatando os parametros
$endPoint = $url . http_build_query($paramns);
//Fazemos a requisição e armazenamos a resposta
$response = httpGet($endPoint);
//tranformamos o retorno em um objeto StdClass
$obj = json_decode($response);
//Obtemos apenas a latitude e longitude para usar no endpoint abaixo para montar o mapa
$latitude = $obj->Response->View[0]->Result[0]->Location->DisplayPosition->Latitude;
$longitude = $obj->Response->View[0]->Result[0]->Location->DisplayPosition->Longitude;
//EndPoint para retornar o mapa encodado
$endPointMapa = "https://image.maps.ls.hereapi.com/mia/1.6/mapview?apiKey={$apiKey}&lat={$latitude}&lon={$longitude}&vt=0&z=14";
//passamos o cabeçalho necessario para indicar o tipo de saida, no nosso caso, uma imagem png
header('Content-Type: image/png');
echo httpGet($endPointMapa);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment