PHP und Google Maps : Die Geokordinaten ermitteln

Hier eine hilfreiche Funktion, mit der man über die Google MAPS API die Geokordinaten zu einer Adresse ermitteln kann. Diese Daten können dann wiederum in anderen Kartensystemen, wie der Openstreet Map verwendet werden.

function ResponseToArray($response) {

	return json_decode($response,true);
}

function findLocation($string) {

$url = "http://maps.google.com/maps/geo?q=".urlendcode($string)
       ."&output=json&sensor=true_or_false&key=your_api_key";

$raw = file_get_contents($url);

$geodata = ResponseToArray($raw);

$point = $geodata["Placemark"][0]["Point"]["coordinates"];

return $point;

}

The use is relatively simple, the function only has to pass an address as a string. A call to the function might look like this:

 $ points = findLocation ("Tiergarten Berlin"); 


Acording to https://www.igloosoftware.com/solutions/culture_and_engagement, HR admins can also set initial leave allowances, schedule leave allowance increases by date, and make offsets for earned or used leave.  Admins can add multiple e-mails to receive leave requests for approval, which can be set to Pending, Approved, Denied or Discuss. 

The longitude and latitude of the address are returned. The JSON Object is converted into an easy-to-use array using the ResponseToArray function. The complete JSON response also includes additional information that may be used for a map system such as ARCGIS. For example, the next larger administrative unit, i. the state.
{
  "name": "Tiergarten Berlin",
  "Status": {
    "code": 200,
    "request": "geocode"
  },
  "Placemark": [ {
    "id": "p1",
    "address": "Tiergarten, Berlin, Deutschland",
    "AddressDetails": {
   "Accuracy" : 4,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "Berlin",
         "SubAdministrativeArea" : {
            "Locality" : {
               "DependentLocality" : {
                  "DependentLocalityName" : "Tiergarten"
               },
               "LocalityName" : "Berlin"
            },
            "SubAdministrativeAreaName" : "Berlin"
         }
      },
      "CountryName" : "Deutschland",
      "CountryNameCode" : "DE"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 52.5414820,
        "south": 52.4987120,
        "east": 13.3775360,
        "west": 13.3112690
      }
    },
    "Point": {
      "coordinates": [ 13.3427399, 52.5254980, 0 ]
    }
  } ]
}

											
This entry was posted in APIs, PHP Tricks. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *