0

I have a question with my Google Maps API. I am using a simple geocoding script to pull a txt/xml file from my server and geocoding the addresses. I have a problem with the addresses coming back as a null value and breaking the script and my database because the coord_lat and coord_long are floats and cannot accept null values.

The error I am receiving is: Warning: file_get_contents(http://maps.google.com/maps/geo?key=AIzaSyBmT9F_ixjLlW8oDiYVqgHqt14a008kXwc&output=xml&q=131+rochestor+ave+039482) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /includes/sfupdate/func.php on line 294 {"status":"Failed","data":"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'coord_lat' cannot be null"} ErrorSyntaxError: Unexpected token

Is this a problem with my connection with Google Maps API? I see HTTP Request failed which leads me to believe that I am being rejected and the addresses are turning back a null value because of it. Advice would be appreciated, thank you.

chronotrigga
  • 589
  • 1
  • 10
  • 33

1 Answers1

0

Sorry for posting a new answer, but here is my current geocoding script.

function get_lat_long($address, $zipcode) {
    if(strlen($zipcode) == 4){
        $zipcode = '0' . $zipcode;
        //echo $zipcode . "\n";
    }   



    $apikey = "IzaSyBmT9F_ixjLlW8oDiYVqgHqt14a008kXwc";
    $geourl = "http://maps.google.com/maps/geo?key=" . $apikey . "&output=xml&q=" . urlencode($address) . "+" . urlencode($zipcode);
    //echo $geourl;
    //echo "<br>";

    // Grab XML content using $geourl
    $context  = stream_context_create(array('http' => array('header' => 'Accept: application/xml')));

    $xml = file_get_contents($geourl, false, $context);
    $xml = simplexml_load_string($xml);


    //Parse the lat and long from the XML
    $Lat = $xml->results->result->locations->location->displayLatLng->latLng->lat;
    //echo $Lat;
    $Lng = $xml->results->result->locations->location->displayLatLng->latLng->lng;
    //echo $Lng;


    //Return
    if($Lng && $Lat) {
        return array('lat'=>$Lat,
                     'lng'=>$Lng
                     );          
    } else {
        return false;
    }


} 
chronotrigga
  • 589
  • 1
  • 10
  • 33