Posted by ekes on March 9, 2010 at 5:03pm
7 followers
| Project: | Geocode |
| Version: | 6.x-1.0-alpha2 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Issue Summary
Google just depreciated v2 of it's geocoder, and made a new one... Blog post http://googlegeodevelopers.blogspot.com/2010/03/introducing-new-google-g... and specs now at http://code.google.com/apis/maps/documentation/geocoding/
So some changes may be in order, but I guess not urgent?
Comments
#1
Nice.. it's more easy to parse, They remove this "no end" array.
I think the change is really easy to do but as you say is not so urgent.
So I just want to keep an eyes on this issue :)
#2
+1 from me
#3
Attached is a patch that replaces the now deprecated Google geocoding API v2 implementation with version 3.
Overall, this change is backwards compatible except for one issue: While ThoroughfareName in v2 contained the street + street number as one element, the new API returns these as separate elements. Since different countries use a different order for these elements ("1600 Pennsylvania Av" versus "Rue Montoyer 100", we can't just concatenate the street and number.
I've added "street_number" to the items returned by get_field_postal(), and I've added an additional property called "formatted_address" to the geocode_google class, allowing clients to request the full formatted address. This way they can request the full address without having to piece it together from the field_postal elements, and without having to worry about where to stick the street number.
#4
work ok except line 104
'lng' => $result->geometry->location->lng,
need to be
'lon' => $result->geometry->location->lng,
I'm not a big fan of the 3 foreach. I will see if I can improve that.
#5
Applied patch in #3 with changes suggested in #4.
Seems to work well except for the 3rd foreach gives "Invalid argument supplied for foreach()" warnings.
I'm using it as an exposed filter in a view with filter function set to distance and widget set to Google API: textfield.
I'm seeing the $google_type variable set to 'political', which isn't present in your $translate_map array. You can get rid of the warning by type casting $translate_map[$google_type] to an array, but not being that familiar with the geocode module or the API, I'm not sure if political should be used for something.
Note: I applied the patch to version 6.x-1.0-alpha2, because it's more recent than the 6.x-1.x-dev version. Should this issue be set to the dev or alpha2 version?
#6
based on #3
This patch integrate what I say in #4. It's also replace the "translate_map" and foreach with a switch. A switch will be more flexible and easy to understand. As a side effect it's correct the warning bug #5.
I also move the all attributes in the main class (street_number and formatted_address).
I can see some improvement (like language) but the patch target is only to pass from the API v2 to v3.
#7
upload fail apparently with # in the name... so same patch
#8
OMG... I saw now (after my vacation) than their are a big mistake in those patch.
So I quickly fix it but I'm not sure is the right way. I can provide a patch but want to take more time to check if this is all right.
<?php
$this->result = $result;
// Store the formatted address if present.
$this->formatted_address = $result->formatted_address;
// Translate the values returned by the Google Geocoding API to values used
// by the Geocode module.
foreach ($result->address_components as $component) {
switch ($component->types) {
case in_array('postal_code',$component->types):
$this->zip = $component->long_name;
break;
case in_array('country',$component->types):
$this->country = $component->short_name;
$this->country_name = $component->long_name;
break;
case in_array('administrative_area_level_1',$component->types):
$this->state = $component->long_name;
break;
case in_array('locality',$component->types):
$this->city = $component->long_name;
break;
case in_array('route',$component->types):
$this->street1 = $component->long_name;
break;
case in_array('street_number',$component->types):
$this->street_number = $component->long_name;
break;
default:
break;
}
}
?>
#9
Subscribing... is anyone interested in a D7 version of this? I know I am! :-)
--Ben
#10
sub