I'd like to be able to have a proximity search that attempts to geocode a user-entered string and then use the result for a proximity search.

The main benefit here is that a user could search for their specific address, or even just see which location are near their municipality. For example, they could search "Toronto, ON", and Google Maps (as an example) would return GPS coordinates corresponding to a central point in Toronto, and then Location could use those coordinates to find all nearby nodes.

I understand there would be some additional latency using an outside site to geocode every such request, but I think the additional flexibility it would offer make it worth it. Can anyone see any other problems such an approach might create?

Has anyone tried something like this? Any code to share?

Comments

yesct’s picture

Issue tags: +location geo-coding

tagging.

related to this collection of geo-coding issues:
#132541: refactor google geocoding

yesct’s picture

gaëlg’s picture

Status: Active » Needs review
StatusFileSize
new5.31 KB

This should work. Please be kind, that's my first patch. :)

gaëlg’s picture

StatusFileSize
new5.32 KB

Oops, this one is the right.

rooby’s picture

subscribing so I remember to review this.
Seems pretty useful.

rooby’s picture

Title: Geocode natural text for proximity search » Geocoded address option for proximity views filter
Version: 6.x-3.1-rc1 » 6.x-3.x-dev
Status: Needs review » Needs work

At a quick glance the patch still applies cleanly enough (one little offset) to the latest dev and coding standards look good.

However, I don't see why not just call google_geocode_location() instead of duplicating the function as location_views_proximity_geocode($address, $country).

You could just say

<?php
$location = array(
  'street' => $options['address_string'],
  'country' => $options['country'],
);
?>

and pass that into google_geocode_location().

When I get some more time I will do a proper test.
Marking as needs work though to get rid of the duplicate function location_views_proximity_geocode($address, $country).

gaëlg’s picture

StatusFileSize
new3.94 KB

Well, I don't remember why I created this new function. You're right, it seems to be useless.

gaëlg’s picture

Status: Needs work » Needs review
StatusFileSize
new4.03 KB

Previous patch is bad. This is the good one, done with CVS.

dufferin’s picture

It works fine!
One thing though, do you think there is a way to integrate the "country" field in the address field.

Few reasons for that. My site is not intended worldwide and the list of the country is exhaustive. But if there is a way to reduce it to few less countries let me know.
And I don't know how to reduce the size length of the dropdown list, and since I want to have it in a block the dropdown goes over the block limits. Again if you have a way to reduce it if the "country" field has to stay on his own.

If I know a little to play around with drupal, I don't know s... about programming, but I'm good at copy and paste if I know where the change has to go.

thanks a lot for any answer!

rooby’s picture

@dufferin:
You can use the 'Limit list to selected items' option for the exposed filter to limit the selectable countries.
- I believe that option had an issue until recently so you will need to use the dev version to use it.

To reduce the size of the field you can either use css in your theme to set the height or you can use hook_form_alter() in a custom module and set the #size attribute to whatever you require.

I can give code examples later when I have some spare time if you need.

dufferin’s picture

@rooby,

You're right I can select the country I want within the "location : country" filter.

In my case I want to use the "location : proximity/distance" filter in view, set to "address/country" since possible with the above patch.

And within that filter, you have a textfield for the address, and a country dropdown list. And that dropdown list cannot, from the filter itself in view, be narrow down to few countries only... It has to come from somewhere else.

I did change the class from "select" to "textfield".
I got then a good width, so one problem solved. I can enter text for countries, so it looks like it's a kind of a fix, but it's not that convenient. Only the country code works, in my case it would be us or ca (bad thing it's case sensitive). Wouldn't be too bad if I could set that 'country' to a autocomplete field limited to US and CA.

And it was my bad explanation, but with the dropdown list, it actually is the width that bothers me (beside the all countries). But I assume the fix is the same regarding the process.

I tried (the class of the dropdown list is 'select') :
input.form-select {
width : 200 px;
}

and

.location .form-select input {
width : 200 px;
}

But without success, told you I'm bad at it.
Sure if you have some spare time send me those code example, it won't hurt.

kay.beissert’s picture

I need this function for drupal 7. Can I use the patch on the location module for d7.

gaëlg’s picture

Probably you won't be able to use the patch out of the box. Anyway it shouldn't be too hard to port this to D7 for someone who's got a bit of time and some PHP skills.

kenneth.venken’s picture

Thanks for the patch.
It works for me!

podarok’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev

all feature requests should be rolled against latest 7.x-3.x-dev and after commit can be backported to 6.x branch

Status: Needs review » Needs work
Issue tags: -location geo-coding

The last submitted patch, location-431912.patch, failed testing.

dom.’s picture

Issue summary: View changes

Also this is an old story, just warning people that I made a patch that could help this issue, or complete it at least:
#2696207: Add an address autocomplete for View proximity filter.