Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when Google maps can't find the location #48

Open
Jammooka opened this issue Sep 2, 2015 · 2 comments
Open

Error when Google maps can't find the location #48

Jammooka opened this issue Sep 2, 2015 · 2 comments

Comments

@Jammooka
Copy link

Jammooka commented Sep 2, 2015

Using the fieldtype in a field called groupAddress works brilliantly, unless Google Maps can't find the location.

{% set location = craft.request.getParam('location') %}
{% set params = {
    address: location,
    distance: 10,
    unit: 'miles'
} %}
{% set locEntries = craft.entries.groupAddress(params).section('groupEntries').relatedTo(service).order('distance asc') %}

If I enter something like "lalalala", which returns no results on google maps, this then throws the common "Column not found" error.

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'order clause'. 

If I leave off the .order('distance asc') parameter, then it doesn't throw an error, but it just shows all results. Outputting {{ locEntries | length }} returns the correct amount of results (even showing 0 when no results are found close to the entered location), but then if entering e.g. lalalala again, it shows the total of all entries, when I'd expect 0.

I can't see any way to check if the location is a valid one before trying to filter the results by it, else it'd be a simple conditional workaround, though obviously it returning 0 results and not throwing an error would be preferable.

@kblizeck
Copy link

Any solution to this? Getting the same error, but there's no way to check if Google returns results before doing the select with .order('distance asc') added to the query...

Hoping to fix this before my site goes live!

@objectivehtml
Copy link
Owner

Sorry for the delayed reply on this. Was out with some serious health and personal issues most of last year. Im starting to get back into full health again and working my plugins. I have been working with a couple other users getting this same issue address. From what I can tell, the plugin code is working in the most recent 2 master branches. However, I think you need to conditionally order by distance only if there is an address available. Something like this...

.order((address ? 'distance' : 'title') ~ ' asc')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants