Source for file google_geocoder.class.php
-
-
-
* This class accepts a street address and attempts to return lat/long coordinates using the Google Maps API.
-
-
-
-
-
-
-
-
-
-
* Sets the API Key issued by Google.
-
-
-
-
-
-
* Sets the street address to geocode. If the address is not broken down into street, city, state, etc, put the entire address in this field.
-
-
-
-
-
-
* Sets the city to geocode.
-
-
-
-
-
-
* Sets the state to geocode.
-
-
-
-
-
-
* Sets the country to geocode.
-
-
-
-
-
-
* Sets the zip code to geocode.
-
-
-
-
-
-
* Gets the raw request sent to Google.
-
-
-
-
-
-
* Gets the raw response received from Google.
-
-
-
-
-
-
* Constructor for the class.
-
* @param string The Google API key.
-
-
-
-
// $Key - the Google API key for this site
-
-
-
-
-
-
-
* 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.
-
-
-
-
-
-
//build the parameters into the URL
-
-
-
//Submit the request to Google
-
-
-
-
-
-
-
-
-
-
//if successful, the response will be in this format: Specificity, Location, Latitude, Longitude
-
if(strpos($LastResponse,",")>
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)
-
-
-
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));
-
-
-