The filter for proximity doesn´t entirely work.

I have setup a range of nodes+node locations. I can filter them by postal code, but when I expose the filter, it doesn´t work. It happens only with the new version of Views, Views Beta3. It worked with the alpha version of Views. The MYSQL Query doesn´t seem to be complete.

I have setup the view exactly the same way in both cases.

This is the mysql query in the VIEWS BETA3 + LOCATION 7x3xDEV modules:

SELECT node.title AS node_title, node.nid AS nid, node.language AS node_language, location.lid AS location_lid, (IFNULL(ACOS(0.76108451683096*COS(RADIANS(location.latitude))*(0.99791696961482*COS(RADIANS(location.longitude)) + -0.064511407942971*SIN(RADIANS(location.longitude))) + 0.64865272545498*SIN(RADIANS(location.latitude))), 0.00000)*6369113.11859) AS location_distance
FROM 
{node} node
LEFT JOIN {location_instance} location_instance ON node.vid = location_instance.vid
LEFT JOIN {location} location ON location_instance.lid = location.lid
WHERE (( (node.type IN  ('beauty_salon')) AND (node.language IN  ('en')) ))
ORDER BY location_distance ASC

and this is the MYSQL query in the Location+VIEWS 7.x-3.0-alpha1 combination:

SELECT node.title AS node_title, node.nid AS nid, node.language AS node_language, location.lid AS location_lid, (IFNULL(ACOS(0.761084516831*COS(RADIANS(location.latitude))*(0.997916969615*COS(RADIANS(location.longitude)) + -0.064511407943*SIN(RADIANS(location.longitude))) + 0.648652725455*SIN(RADIANS(location.latitude))), 0.00000)*6369113.11859) AS location_distance_sort FROM  {node} node LEFT JOIN {location_instance} location_instance ON node.vid = location_instance.vid LEFT JOIN {location} location ON location_instance.lid = location.lid WHERE (( (node.type IN ('beauty_salon')) AND (location.latitude > '39.9903059828' AND location.latitude < '40.8898940172' AND location.longitude > '-4.28979530113' AND location.longitude < '-3.10780469887') AND ((IFNULL(ACOS(0.761084516831*COS(RADIANS(location.latitude))*(0.997916969615*COS(RADIANS(location.longitude)) + -0.064511407943*SIN(RADIANS(location.longitude))) + 0.648652725455*SIN(RADIANS(location.latitude))), 0.00000)*6369113.11859) < '50000') AND (node.language IN ('en')) )) ORDER BY location_distance_sort ASC

I hope this will provide the info to fix it, but if you need more info let me know,

Comments

Ciraxis’s picture

subscribe

k3vin’s picture

+1

WillHall’s picture

+1

naterockhold’s picture

subscribe

WillHall’s picture

Problem exists in 7.x-4.x as well.

WillHall’s picture

Location 7.x-3.x-dev
Views 7.x-3.0-beta3

Filter Criteria:
Node published,
Type = dealers,
Distance/Proximity
Exposed
(circular)
Postal Code (assume default country)

In testing - the sql query doesn't bother to update when apply is pressed. its as if the filter is not meeting some condition.

Here is just that filter with postal code set to 90210 and distance set to 10 miles.

SELECT node.title AS node_title, node.nid AS nid
FROM 
{node} node
WHERE (( (node.status = '1') AND (node.type IN  ('dealers')) ))

Adding the stand alone postal code filter by itself yields this query.

SELECT node.title AS node_title, node.nid AS nid
FROM 
{node} node
LEFT JOIN {location_instance} location_instance ON node.vid = location_instance.vid
LEFT JOIN {location} location ON location_instance.lid = location.lid
WHERE (( (node.status = '1') AND (node.type IN  ('dealers')) AND (location.postal_code LIKE '90210' ESCAPE '\\') ))

Which works, shame distance isn't stand alone as well.

rooby’s picture

WillHall’s picture

Thanks, working perfectly now.

Ciraxis’s picture

:top:

lut4rp’s picture

Status: Fixed » Active

For me proximity filter is still not working with latest views (7.x beta3 and dev both). Proximity query looks like:

SELECT node.title AS node_title, node.nid AS nid, location.latitude AS location_latitude, location.longitude AS location_longitude, location.postal_code AS location_postal_code, node.created AS node_created, 'Unknown' AS location_distance
FROM 
{node} node
LEFT JOIN {location_instance} location_instance ON node.vid = location_instance.vid
LEFT JOIN {location} location ON location_instance.lid = location.lid
WHERE (( (node.status = '1') ))
ORDER BY node_created DESC
LIMIT 10 OFFSET 0

this is missing:
AND (location.postal_code LIKE '90210' ESCAPE '\\') )) part.

Anonymous’s picture

subscribe

Sinan Erdem’s picture

I am sorry but I have this biig confusion:

In order to make the proximity search work, I imported certain country's zipcode table into "zipcodes" table in the db. That mysql file is coming with the locations module.

Normally my location nodes doesn't have coordinate information. If they had, I wouldn't need these database imports.

But the views query indicates that, it is looking into the location.latitute and location.longitute which are 0 for any location.

Shouldn't there be a query which also looks up for the "zipcodes" table and relates the zipcode with coordinate information? Am I missing anything here?

kevinwalsh’s picture

Your location get their location info from a 3rd party geocoding service, not from the zipcodes table in the databsae. if you're using drupal 7, you need to configure geocoding here: admin/config/content/location/geocoding

the database import is for doing proximity searches against the zip code data stored locally.

Sinan Erdem’s picture

I exactly want to do proximity searches against the zipcode data stored locally (on my zipcodes table on db). But this Views query doesnt seem to look into that table... I couldn't find any way to use this table...

cwightrun’s picture

I too am experiencing issues with the Proximity filter. It doesn't appear to change anything on the map - all locations are shown in their most out-zoomed display.

I'm currently experiencing the exact same situation as #6.

Current config w/query: http://cl.ly/1c263z401Y2w1N11062v
Current Filter for Zip: http://cl.ly/0J1U1E2e2m1o1o200B1W

---EDIT---
Ah hah. Got it.

Had to:
1) Create "zipcodes" table in my Drupal DB, set up proper columns.
2) Import the corresponding mysql rows for the table (in my case, zipcodes.us.mysql)
3) Clear Province and Supported Country List caches at /admin/config/content/location/util
4) Clear site-cache
5) Test, and viola!

Thanks!

rooby’s picture

@etcetera9:
The zipcodes database you loaded in from the files in the location module stores lat/lon coords of the postal/zip codes for whatever country(ies) you added.
The way that the post code proximity stuff works is that it calculates the distance from your locations' lat/lon coords and the coords of the post code.
For this to work your locations must have lat/lon values. Otherwise you are checking the proximilty of the point 0,0 (which is what the location module defaults to).
So for it to work either your users have to enter lat/lon values, or you have to set up geocoding, which will use google to try to auto calculate the lat/lon values from whatever address has been entered.
You can set the precision of the geocoding to different levels depending on what values your users are entering. For example, state level or street level etc.
The settings for this in d7 are at admin/config/content/location/geocoding

Sinan Erdem’s picture

Thank you rooby, I did exactly as you are saying some time ago and now, all works ok. I had to geocode each location by using Google. I had 11000 locations coming from a feed :O so the import took ages :) But in the end it finished and works flawless ;)

Thanks...

rooby’s picture

Status: Active » Postponed (maintainer needs more info)

@lut4rp:
I have tested with latest dev of location and latest dev of views (also with a version of views from 5th apr 2011) and it is working.
I have tried using views 7.x-3.0-beta3 and found it too buggy to use, especially on a live site.

The query for a view using the postal code proximity filter in it will not have anything resembling
AND (location.postal_code LIKE '90210' ESCAPE '\\') ))
because it actually looks up the lat/lon of the post code, then uses those coords in the query.
The proximity part will actually look something like:

(location.latitude > '-41.2002426543' AND location.latitude < '-26.7280353457' AND location.longitude > '142.351769386' AND location.longitude < '159.822294614') AND ((IFNULL(ACOS(0.829387404805*COS(RADIANS(location.latitude))*(-0.875355121198*COS(RADIANS(location.longitude)) + 0.483480518523*SIN(RADIANS(location.longitude))) + -0.558673905557*SIN(RADIANS(location.latitude))), 0.00000)*6371439.33236) < '804673.5')

Can you post an export of your view?
If it is really big just put it in a txt file and attach.

rooby’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closing due to inactivity.
Please feel free to reopen if this is still an issue.

astanley86’s picture

Status: Closed (cannot reproduce) » Needs review

I can't get this to work still, I've tried both 7.x-3.x-dev and 7.x-4.x-dev versions and I have followed all suggestions according to this thread but I can't get proximity/distance to show a value- I've used each of the different proximity/distance filters and can't get it to work whether or not they are exposed. If you have any suggestions for me let me know- but I think it's an issue with the release..
http://ScrnSht.com/qnzmad
http://ScrnSht.com/xmpbiq
http://ScrnSht.com/xmiowy

hellomobe’s picture

This is a little off topic of the title, but inline with coming up with the solution to get the long/lat so that proximity will work. Can locations or gmap set the long/lat based on the address input? I'd like to avoid having the user input the address AND have to set the map (seems redundant).

rooby’s picture

Status: Needs review » Active

@astanley86:
It seems like you are referring to the distance/proximity field, not the filter. Is that right?
This issue is specific to the filter, not the field.
If it is the field you should open a new issue (last time I checked there was not one already for the field although I haven't looked for a little while).

It will also be helpful if you can post an export of your view and if possible the sql for your view (it should show it when you do a preview).

@hellomobe:
You're right, it isn't this issue.
There is one for that here #431912: Geocoded address option for proximity views filter
Although that is drupal 6 so it will need porting for drupal 7.

astanley86’s picture

Thanks @rooby It was a fields issue and it was because the zip code table was empty. Importing these values into the table resolved my issue.

BeaPower’s picture

How do you import the .mysql file? I have zipcodes.us.mysql which I am trying to import through phpmyadmin and bigdump - but no results are imported. BigDump says it doesn't support .mysql files.

Luttappi’s picture

Issue tags: +location, +UK Location

Hi,

When I try the proximity search with UK with views I get the following error.

"Recoverable fatal error: Argument 2 passed to db_query() must be an array, string given, called in /home/halalfi1/public_html/sites/all/modules/location/location.inc on line 299 and defined in db_query() (line 2311 of /home/halalfi1/public_html/includes/database/database.inc)"

The versions are...

Core: 7.8
Location : 7.x-4.x-dev

From suggestions by some other posts on the site, I have made the following changes.

* Renamed "location.uk.inc" to "location.gb.inc"
* Updated the country codes within "Zipcodes" tables from "uk" to "GB"

GMap is also installed. any help would be appreciated.

The error can be visible here http://www.halalfinder.co.uk/proximity

Thanks,

ankur’s picture

Status: Active » Closed (fixed)

@Luttapi in #26:

Don't use 7.x-4.x yet. It's still in development.

Use 7.x-3.x, as stated on the project home page.