Google has deprecated the V2 API we currently use for geocoding. (And it seems to be down at the time of writing, although they claim it shouldn't be). We should move to the V3 API. See here: https://developers.google.com/maps/documentation/geocoding/v2/

I'm in the process of porting locationmap to D8 as a personal D8 learning exercise, so I'll backport the API fix when I'm done with that.

Comments

Bonno’s picture

Here is a patch to upgrade the geocoder api from v2 to v3 for the current 7.x-2.2 version.

--- locationmap.module	2012-08-10 20:48:08.000000000 +0100
+++ locationmap.module	2014-01-20 10:15:06.000000000 +0100
@@ -289,31 +291,32 @@
  * @returns FALSE if address not found
  */
 function locationmap_geocode_for_address($address) {
 
   $url_options = array(
     'query' => array(
-      'q' => $address,
-      'output' => 'csv',
+      'sensor' => 'false',
+      'address' => $address
     ),
   );
 
   $options = array(
     'max_redirects' => 10,
     'timeout' => 120, 
   );
 
-  $response = drupal_http_request(url('http://maps.google.com/maps/geo', $url_options), $options);
-
+  $response = drupal_http_request(url('http://maps.googleapis.com/maps/api/geocode/json', $url_options), $options);
+  
   if ($response->code != 200) {
     return FALSE;
   }
 
-  // data looks like: 200,5,51.4793862,-2.5729730  
-  $data = explode(',', $response->data);
-  return array($data[2], $data[3]);
+  // data is json response: https://developers.google.com/maps/documentation/geocoding/#GeocodingResponses
+  $data = json_decode($response->data);
+  $location = $data->results[0]->geometry->location;
+  return array($location->lat, $location->lng);
 }
 
 /**
  * Try to get lat and lng information from address removing parts of address if not found.
  */
 function locationmap_geocode_for_address_recursive($address) {
rupertj’s picture

Issue summary: View changes
Status: Active » Fixed

Thanks! Works for me, so commited to 7.x-2.x branch.

rupertj’s picture

Status: Fixed » Closed (fixed)