Beitragsseiten

ACHTUNG. Die Abfragen sind (Stand: 20.02.2015) für Privatpersonen auf 2500 und für Geschäftskunden 100000 pro Tag begrenzt. Die kompletten Nutzungsbedingungen wechseln ständig und sind hier zu finden: Google Geocoding API

function getGoogleCoordinates($street, $zip = '', $city = '', $country = 'Germany')
{
  $address = $street . ', ' . $zip . ' ' . $city . ', ' . $country;

  $url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=true';

  $curl = curl_init();
  $timeout = 5;
  curl_setopt($curl, CURLOPT_URL, $url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_HEADER, 0);
  curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
  $response = curl_exec($curl);
  curl_close($curl);

  $response = json_decode($response);

  $coordinates['lat'] = $response->results[0]->geometry->location->lat;
  $coordinates['lon'] = $response->results[0]->geometry->location->lng;
  return $coordinates;
}