Created
April 3, 2021 11:56
-
-
Save gaffling/2db726d73c1938b0fff2c58a33bdde5b to your computer and use it in GitHub Desktop.
[getLatLong] Get lat and long coordinatesby address from Google Maps #php #function #geo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ---------------------------------------------------------------------------------------- */ | |
/* [getLatLong] Get lat and long coordinatesby address from Google Maps #php #function #geo */ | |
/* ---------------------------------------------------------------------------------------- */ | |
function getLatLong($address){ | |
if (!is_string($address)) die('ERROR - Address must be a string!'); | |
$url = sprintf('https://www.google.com/maps/place/%s', rawurlencode($address)); | |
$result = file_get_contents($url); | |
preg_match('!center=(-?\d+\.\d+)%2C(-?\d+\.\d+)&zoom=!U', $result, $match); | |
$_coords['lat'] = $match[1]; | |
$_coords['long'] = $match[2]; | |
return $_coords; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment