/ Published in: PHP
Simple function to get Infos from google geocode with a query as an Array The standard API Key is the Key for LOCALHOST.
Expand |
Embed | Plain Text
function geoCode($QUERY,$GOOGLEKEY="ABQIAAAAmYQAbPSpbkj2fDNP_JB0UBT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQQxl2km_LSoDtKnqMEqRRfxbaqjQ") { $page = file_get_contents("http://maps.google.com/maps/geo?q=".urlencode($QUERY)."&key=".$GOOGLEKEY."&output=xml"); $xml = new SimpleXMLElement($page); $xml->Response->Placemark->Point->coordinates); $RETURN["LandCode"] = (string) $xml->Response->Placemark->AddressDetails->Country->CountryNameCode; $RETURN["LandName"] = (string) $xml->Response->Placemark->AddressDetails->Country->CountryName; $RETURN["AdArea"] = (string) $xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->AdministrativeAreaName; $RETURN["SubAdArea"] = (string) $xml->Response->Placemark[0]->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->SubAdministrativeAreaName; $RETURN["DependentArea"] = (string) $xml->Response->Placemark[0]->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->DependentLocality->DependentLocalityName; $RETURN["Locality"] = (string) $xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->LocalityName; $RETURN["PostCode"] = (int) $xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->PostalCode->PostalCodeNumber; if (!$RETURN["PostCode"]) $PLZ = (int) $xml->Response->Placemark[0]->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->DependentLocality->PostalCode->PostalCodeNumber; $RETURN["LAT"] = $latitude; $RETURN["LON"] = $longitude; return $RETURN; }
You need to login to post a comment.
