Last active
December 15, 2015 06:49
-
-
Save Dianakc/8b663c7a212818e50507 to your computer and use it in GitHub Desktop.
Convert an address into latitude, longitude values
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
<?php | |
/ * Convert an address into latitude longitude */ | |
function getLatLong($address){ | |
$_url = sprintf('http://maps.google.com/maps?output=js&q=%s',rawurlencode($address)); | |
$_result = false; | |
if($_result = file_get_contents($_url)) { | |
if(strpos($_result,'errortips') > 1 || strpos($_result,'Did you mean:') !== false) return false; | |
preg_match('!center:\s*{lat:\s*(-?\d+\.\d+),lng:\s*(-?\d+\.\d+)}!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