The distance query works well, but I wanted to get the visitor's location from their IP address. Instead of writing a views_query_alter or something, I thought it would be nice to have this functionality within location itself. So, I modified the filter handler for proximity, and got it to support the geoip api module with a checkbox. A patch is attached - no simpletests yet but I hope it's useful anyhow.
The only thing that I wanted to get working but didn't was a way to expose the zipcode filter but still have the map come up with the user's location by default.
Oh, also there's some stuff you have to do to make the City-level database work with geoip module - described at http://drupal.org/node/813228#comment-3057436
Comment | File | Size | Author |
---|---|---|---|
#35 | location-geoip-views-filter-820116-35.patch | 3.74 KB | dnotes |
#7 | 820116-location-3.1-geoip-views.patch | 2.61 KB | dnotes |
#5 | location_geoip_origin.patch | 1.35 KB | gamelodge |
location_geoip_support.patch | 2.21 KB | dnotes | |
Comments
Comment #1
jkdaza CreditAttribution: jkdaza commentedThis is great! Thanks.
Would it be too much of a problem adding the same feature to the "Sort Criteria"?
Comment #2
dnotes CreditAttribution: dnotes commentedIf you mean sorting by proximity to a visitor's location, you should already be able to do that: add a "Location: Distance / Proximity" sort, and on the extra settings screen (the gear on the right side) select "Use Distance / Proximity filter". According to the documentation, sorts were kind of touchy to set up, but I didn't experience any of the problems described.
Comment #3
SeanBannister CreditAttribution: SeanBannister commentedAwesome, I was just about to code this. I'll give you my review soon.
Comment #4
dnotes CreditAttribution: dnotes commentedHey, it's a little off topic for location module alone, but I just rediscovered that if you're using a gmap view this patch alone will not center a map on the visitor's IP address - for that something else is needed. What I've done is included an id of "iploc_block" in the gmap macro for that view display (click on the gear to the right of gmap style, and in the gmap macro, between the brackets, enter " |id=iploc_block"). Then I include a hook_gmap somewhere in my module:
-et viola, the map is centered on a visitor's ip address. This is a hack, but I'll bet there's a way this could get into location.module as well, and it would be *awesome*.
Comment #5
gamelodge CreditAttribution: gamelodge commentedHi Guys
I could not get the patch above to work on my install.
So I created a separate patch that does the job for me.
You need the GeoIP module for this to work.
All this does is add a an extra option to the views proximity filter to allow you to set the origin as the IP address as referenced from the GeoIP module.
Comment #6
dnotes CreditAttribution: dnotes commentedUpdated patch against version 3.1 - nice job on the changes to proximity filter handler! I like the new options.
Oh, and this patch should be in the right format to apply with drush make this time.... =oops=
Comment #7
dnotes CreditAttribution: dnotes commentedright, and here's that patch.
Comment #8
dnotes CreditAttribution: dnotes commentedWow, posted at exactly the same time... weird. The v3.1 patches above are nearly identical except that the latter should fall back to default coordinates if they were entered. I'm okay with either, but I prefer the latter functionality.
Comment #9
YesCT CreditAttribution: YesCT commentedgamelodge, up for a review of #7?
Comment #10
jusyjim CreditAttribution: jusyjim commentedDavidhunt,
Regarding #4 above...
This is exactly what I need but which module did you put that code in? location module? I tried that and it didn't work using this gmap macro:
[gmap zoom=9 |id=iploc_block |width=99% |height=300px |control=Small |type=Map]
Thanks!
Comment #11
dnotes CreditAttribution: dnotes commentedJusyjim,
You should be able to put the code from #4 in whatever custom module you are using; you just have to adjust the function name accordingly (my custom module was ccd_loc). I wouldn't put it in Location though, because it's better not to change code on contrib modules for custom functionality.
Cheers!
David
Comment #12
izmeez CreditAttribution: izmeez commentedsubscribing
Comment #13
BeaPower CreditAttribution: BeaPower commentedIm a newbie and dont understand how to apply the patch, help plz. How to create custom module?
Comment #14
shopdogg CreditAttribution: shopdogg commentedsubscribe
Comment #15
dnotes CreditAttribution: dnotes commentedBeaPower - I just noticed your post - for patches, the page is http://drupal.org/patch/apply, and for creating a custom module, you could start at http://drupal.org/developing/modules. You won't need everything in that handbook for the present task; all you'll really need is the .info file, the .module file, and an understanding of how to implement a hook. It's hard to know where to find this stuff when you're just starting, isn't it? I wonder if there's a documentation page for the documentation pages... :) As I recall, a while back I found a page that helped explain drupal.org a little, so you might click around for that. Good luck!
Comment #16
barry769 CreditAttribution: barry769 commentedIs there any plan to get the exposing of the zip code filter to work? The functionality sounds good, but won't be very effective when the database returns a bad value.
Comment #17
deggertsen CreditAttribution: deggertsen commentedI applied the patch in #7 successfully. It would be nice if this could be committed with some of the other things discussed in this thread. Subscribing.
Comment #18
dnotes CreditAttribution: dnotes commenteddeggertsen, is there any way you could do a thorough review of this patch? it's really not appropriate to mark it as rtbc on my own.
Comment #19
deggertsen CreditAttribution: deggertsen commentedI don't know if my review would be adequate. I'm not very familiar with geo coding and don't have time to familiarize myself with it. All I really know is that the patch applied correctly and works as far as I can tell at this point. I will likely be doing more testing with it later but the site I'm working on that uses it is still in early dev stages.
Comment #20
bryancasler CreditAttribution: bryancasler commentedAny possibility of a D7 port?
Comment #21
bryancasler CreditAttribution: bryancasler commentedThis might be helpful too.
How to identify city of visitor and switch content
http://drupal.org/node/1081180
Comment #22
Road Runner CreditAttribution: Road Runner commentedHere is php code to get and print the city and state (region). If you uncomment the print_r it will show you the entire array that is returned and you can then get much more location info. Now how one would then switch all the contents needs further exploration - maybe context module.
Forgot to mention this is in D7 which I am switching to.
Comment #23
spyderpie CreditAttribution: spyderpie commentedHas a patch been applied and to which version ... If not, is the patch in #7 the correct one to apply?
Thanks,
Julie
*** Update
After playing .. I realized that its the first patch attached, but it fails at hunk 4 & 5 for me. The second one added by gamelodge in #5 also fails for me. I am running location version 6.x-3.1.
I would really love to have this feature -- any advise?
Julie
Comment #24
dnotes CreditAttribution: dnotes commentedFor Location 6.x-3.1 I am still using the patch in #7 to proper effect, even on production sites.
Comment #25
spyderpie CreditAttribution: spyderpie commentedMaybe its me ....
What directory do I put the patch in and run it from? I've tried both the location and the handlers directory.
Then I run ...
patch p1 < 820116-location-3.1-geoip-views.patch
correct?
Julie
Comment #26
spyderpie CreditAttribution: spyderpie commentedOk humor me .. i am very frustrated! LOL
So if I apply the patch using patch < patchname in each directory (location and location/handlers) it seems that it patches the approriate file in each directory and fails on the other. So I assume both files got patched ...
I see the option in the filter now ....
When I create the view ... do I need an arguement for the view or just the filter? I cannot seem to get it to pull the info from geoip and give me the search result I am looking for.
I am using node locations .. but I tried cck locations also with the same results.
Thanks in advance and thank you for responding so quickly before.
Julie
**** Update
OMGoodness ... your Bahai site is beautiful -- and has the functionality I am looking for. What modules are you using? To get those map results? and are you using cck or node locations?
****** OMG Update!!!!!!
I got it .. you have to have the geolitecity database installed. The other one doesn't work! OMGOMGOMGOMGOGMOGMOMGOMGOMGOMG .. sorry - you have no idea how many hors I have spent on this!
Thank you for this post and patch .. without it - I would still be trying to figure this out!
Comment #27
k1 CreditAttribution: k1 commentedI was able to apply the patch from #5 but got errors with #7.
I am able to see geoip filter but I am not getting any results. My views query returns no values. I have enabled the geoip module and set the path to the geolitecity database sites/all/libraries/geoip/geolitecity.dat.
Am I supposed to import the database to my sql? or Just importing the database to path above is enough?
Thanks in advance for any help.
Comment #28
dnotes CreditAttribution: dnotes commented@k1: I don't know about your situation, but I always have this problem when I am using development environments, because the geoip module can't determine your location unless it has a real ip address. As I recall, there is a debug setting for geoip that will allow you to specify an ip address in the request. Also make sure your view returns nodes without the filter/sort specified.
Comment #29
bkosborneThis is pretty cool. I'm running into an issue where i'd like to have view proximity search based on the IP address, but also give a zip code option. That way if the IP is really inaccurate or something, the user could enter zip code. Has anyone done this?
Comment #30
dnotes CreditAttribution: dnotes commentedHi bkosborne - I think you may have been the one I was communicating with about this before, but it's good to have it up here in any case. I'm sure there are a few different ways to do this. I used the site's search form, and wrote a bit of custom code in case people enter a zipcode:
the result is up at http://find.bahai.us if anyone wishes to see it in action.
Comment #31
bsandor CreditAttribution: bsandor commentedSubscribe
Comment #32
liminu CreditAttribution: liminu commentedHello, i try to apply the path #1 but the location module is change, so i apply the patch in #7 and the filed corrects appears, i enable geoip module and download the .dat in the correct position, but the filters doesn't works. Any idea? Is a php code that i can use for the proximity filter?
Comment #33
dnotes CreditAttribution: dnotes commentedHi @liminu, I'd love to help you out with this but I can't tell what's wrong from your description. There are a few questions that might help: What happens when you try to use the filter? In what way does it not work? Did you try putting geoip in testing mode? I assume that you're not trying it on your local dev environment, because it won't work there.
Comment #34
liminu CreditAttribution: liminu commentedAt end i use smart_ip module that use html5 geolocalization. Thanks
Comment #35
dnotes CreditAttribution: dnotes commentedWell, the site I use this for is being updated to Drupal 7, and so is this issue. Here it is, 2.5 years later, with fresh line numbers on the patch.
Comment #36
podarok#1931088: [META] Fixing tests tests were broken, so triggering to active
Comment #37
podarokbot
Comment #38
podarok#35 commited pushed to 7.x-3.x
thanks!!!