You are here

function gmap_geocode in GMap Module 5

Same name and namespace in other branches
  1. 6.2 gmap.module \gmap_geocode()
  2. 6 gmap.module \gmap_geocode()
  3. 7.2 gmap.module \gmap_geocode()
  4. 7 gmap.module \gmap_geocode()

Utility function to use the google maps geocoder server side. This is an easy, quick way to geocode a single address. Note: This is a REMOTE CALL TO GOOGLE. Do NOT use this where performance matters, as it could possibly take several seconds for this function to return. See http://www.google.com/apis/maps/documentation/reference.html#GGeoStatusCode for a description of the possible status codes.

1 string reference to 'gmap_geocode'
gmap_location_update_5101 in ./gmap_location.install
5.x-1.0 update 2. (Post-release) Delete unneeded variable.

File

./gmap.module, line 1070
GMap -- Routines to use the Google Maps API in Drupal.

Code

function gmap_geocode($address, $tld = 'com') {
  $key = gmap_get_key();
  $data = drupal_http_request('http://maps.google.' . $tld . '/maps/geo?q=' . drupal_urlencode($address) . '&output=csv&key=' . $key);
  if ($data->code == 200) {
    $r = explode(',', $data->data);
    return array(
      'status' => (int) $r[0],
      'accuracy' => (int) $r[1],
      'latitude' => $r[2],
      'longitude' => $r[3],
    );
  }

  // Non 200 is G_GEO_SERVER_ERROR (500).
  return array(
    'status' => 500,
  );
}