Key=$Key; } /** * Submits the address to Google and processes the response. * @return mixed On success, returns an array containing two elements: Latitude and Longitude. Returns false on failure. */ function GeoCode() { $objCurl = curl_init(); //build the parameters into the URL $url="http://maps.google.com/maps/geo?q=".urlencode($this->Address).",+".urlencode($this->City).",+".urlencode($this->State).",+".$this->Country."&output=csv&key=".$this->Key; //Submit the request to Google $this->LastRequest=$url; curl_setopt($objCurl, CURLOPT_POST,1); curl_setopt($objCurl, CURLOPT_URL,$url); curl_setopt($objCurl, CURLOPT_RETURNTRANSFER,1); curl_setopt($objCurl, CURLOPT_SSL_VERIFYPEER, FALSE); $LastResponse = curl_exec ($objCurl); $this->LastResponse=$LastResponse; curl_close ($objCurl); //if successful, the response will be in this format: Specificity, Location, Latitude, Longitude if(strpos($LastResponse,",")>0) { $dLatitude=0; $dLongitude=0; $return_parts=explode("\n",$LastResponse); //there may be multiple rows returned. the last is the most accurate. loop through backwards until we find a positive response (200) while(($last_row=array_pop($return_parts)) && !$dLatitude) { $row_parts=explode(",",$last_row); if($row_parts[0]==200) //200 is the specificity we want { $dLatitude=$row_parts[2]; $dLongitude=$row_parts[3]; } } } return(array("Latitude"=>$dLatitude,"Longitude"=>$dLongitude)); } } ?>