Currently the google_geocode_location() function retrieves the lat/lon values from its google geocoding request.

Google also returns state & city data where it can so if this data is available it should be used.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rooby’s picture

rooby’s picture

Status: Active » Needs review
hutch’s picture

I've created a new instance of drupal and installed location (no gmap this time) plus the two patches.
Created two nodes with full addresses, both geocoded fine as far as lat/lon goes but nothing in zipcodes, kinda thought it might put the finds there. One UK and one US address. I think I will drop some dd() in there and see what is going on.

BTW I see in the location table that column source has 3 in it, not sure what that means as yet so that's another thing to get a grip on.

I enabled google in admin/settings/location/geocoding for UK, US, Germany and Australia, I might try just postcodes next.

Summit’s picture

Subscribing, greetings, Martijn

rooby’s picture

Status: Needs review » Needs work

@hutch:
One thing to look out for is that for certain countries google_geocode_location() is never called because they have their own country specific geocoding functions in location.xx.inc.
If it is running google_geocode_location() it should be adding it to the database if it is working correctly.
So far I have only done tests calling the functionality from a devel execute PHP block. I still have to do a better test of it working via the module.

Also, I have just realised that country specific google geocoding (like _location_latlon_exact_us_geocoder() in location.us.inc) should have this functionality where possible too.
I'll check it out later.

hutch’s picture

Using uk postcodes and having made sure nothing in location.uk.inc would jump in, I found that rough and rough_default were never being reached, location_latlon_exact was being called in _location_geo_logic from location.module. Haven't traced that back yet. I'm using location enabled nodes to test this all.
More later...

hutch’s picture

@rooby:
On saving a node, location_save() runs location_latlon_exact() via _location_geo_logic() which only saves lat/lon. There is a comment in location.module line 1324 // @@@ How about address normalization?
This suggests that this would be a good place to add city and state, so I added

        if ($data['city']) {
          $location['city'] = $data['city'];
        }
        if ($data['state']) {
          $location['province'] = location_province_code($location['country'], $data['state']);
        }

I now am saving province to the location table when I supplied country and postcode only. 'city' was not supplied by google in this particular instance. I only ran one test on UK postcode. I will try some other countries too.

rant start
UK postcodes are a pain because they are in two parts and the Royal Mail are being despicably duplicitous, insisting on the right to sell data already paid for by the taxpayer ;-| grrrrrr. Oh well
rant end

Now none of this addresses the original idea of saving geocode stuff to zipcodes table.
I would suggest some new functions: (in location.inc)
1) location_insert_zipcodes
2) location_update_zipcodes
3) a handling function function which would ensure that the zipcodes table was updated sensibly, preserving existing data etc

or perhaps all three rolled into one.

3) could be called in _location_geo_logic() or perhaps even better in location_latlon_exact()

This way it doesn't matter if rough and rough_default are used or not.

Summit’s picture

Will this patch bring europe/worldwide google geocoding available to location?
Greetings, Martijn

legolasbo’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Closing old D6 issues as D6 is end of life