You are here

function gmap_geocode in GMap Module 6.2

Same name and namespace in other branches
  1. 5 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 1142
GMap -- Routines to use the Google Maps API in Drupal.

Code

function gmap_geocode($address, $tld = 'com') {
  $result = drupal_http_request('https://maps.googleapis.' . $tld . '/maps/api/geocode/xml?address=' . drupal_urlencode($address) . '&sensor=false');
  $data = new SimpleXMLElement($result->data);
  if ($data->status == 'OK') {
    $r = explode(',', $data->data);
    return array(
      'status' => (string) $data->status,
      'latitude' => (double) $data->result->geometry->location->lat,
      'longitude' => (double) $data->result->geometry->location->lng,
    );
  }
  return array(
    'status' => $data->status,
  );
}