views:

32

answers:

1

I have no idea where to begin - my web host does not allow fopen, but my geocoding script below uses it. So, since no fopen - no lat & long - so no google maps on my pages.

Can anyone redo this in curl?

http://paste.ly/4HU (since the code is breaking up below)

    $mapaddress=str_replace(' ', '%20', $_REQUEST['street_num'] . ' ' . $_REQUEST['address2'] . ', ' . $loccity . ', ' . $ststate . ', ' . $_REQUEST['postcode'] . ', ' . $cncount); 

$key=$er_mapapi; 
$file = "http://maps.google.com/maps/geo?q=$mapaddress&output=xml&key=$key"; 
$longitude=''; 
$latitude=''; 

if ($fp = fopen($file, "r")) { 

    $coord='<coordinates>'; 
    $coordlen=strlen($coord); 
    $r = ""; 
    while ($data = fread($fp, 32768)) { 
        $r .= $data; 
    } do { 
        $foundit=stristr($r,$coord); 
        $startpos=strpos($r,$coord); 
        if (strlen($foundit) > 0) { 
            $mypos=strpos($foundit,"</coordinates>"); 
            $mycoord=trim(substr($foundit,$coordlen,$mypos-$coordlen)); 
            list($longitude, $latitude) = split(',', $mycoord); 
            $r=substr($r,$startpos+10); 
        } 
    } 

    while (strlen($foundit) > 0); 
    fclose($fp); 
} 

if ($latitude != '') $row->declat = $latitude; if ($longitude != '') $row->declong = $longitude; 
A: 
$curl = curl_init($file);
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
$r = curl_exec($curl);

should do it. Put this before the do { ... } while (); part.

For clarity: You can then leave out all calls to fopen, fread and fclose.

mvds
Any chance you could elaborate? show the whole code? thanks!
Jason
I couldn't get curl to work properly with the above code, so I did this: http://stackoverflow.com/questions/3390015/getting-wrong-latitude-longitude-from-geocoding
Jason