Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
1  
Maybe your server's IP is blacklisted. Sometimes a blank page is a sign of a PHP error, though. Check your logs. –  ceejayoz 1 hour ago
1  
Could also be an unusual setting in your php.ini like json support being disabled. This is unlikely though. –  wogsland 1 hour ago
    
post your log from /var/logs/apache2 –  dave 1 hour ago
    
Is your website on a shared server? Perhaps you need to include a key in your request. –  geocodezip 8 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.