I have a function that takes an array of addresses, passes them into the google maps geocode api and returns a list of latitude/longitude coordinates that are then saved to a database.
It's been working perfectly in my environment (php 5.4) but I recently pushed the site live (the server has php 5.3 installed) and I noticed my lat/lng database hasn't been getting updated.
As a test I pulled out a piece of the code and ran them independently, once from my local environment and once on my server. The live code produces no results and my local code continues to produce the proper results. I'm not sure what's causing the problem as the live site is an exact replica of my local site.
Here's the code
$addr = '210 west 103rd street, ny 10025';
$addrencode = urlencode($addr);
$url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=".$addrencode;
$json_txt = file_get_contents($url);
if (! $json_txt)
return FALSE;
$json_arr = json_decode($json_txt, TRUE);
if ($json_arr["status"] != "OK")
return FALSE;
$result = $json_arr["results"][0];
$ret = array(
"addr" => $addr,
"faddr" => $result["formatted_address"],
"lat" => $result["geometry"]["location"]["lat"],
"lng" => $result["geometry"]["location"]["lng"]
);
print_r($ret);
Any idea what could be causing this to break when ran online? If I actually visit the URL with the encoded address in my browser I can also collect the results.
On local I receive:
Array ( [addr] => 210 west 103rd street, ny 10025 [faddr] => 210 West 103rd Street, New York, NY 10025, USA [lat] => 40.7986924 [lng] => -73.9678981 )
On live I receive a blank page