Skip to content

Instantly share code, notes, and snippets.

@mikestratton
Created January 17, 2022 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikestratton/7e06a9f60c5bc23e692b7607d49301a2 to your computer and use it in GitHub Desktop.
Save mikestratton/7e06a9f60c5bc23e692b7607d49301a2 to your computer and use it in GitHub Desktop.
GIS Function within Laravel Controller
public function geoCoding($zip_code){
$api = 'https://maps.googleapis.com/maps/api/geocode/json?address=';
$par = '&key=';
$goo = env('GOOGLE_KEY');
$url = $api . $zip_code . $par . $goo;
$file = file_get_contents($url);
$json = json_decode($file, true);
$lat = $json['results'][0]['geometry']['location']['lat'];
$lon = $json['results'][0]['geometry']['location']['lng'];
$geo = array($lat, $lon);
return $geo;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment