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

Distance not appearing #28

Closed
andyharris opened this issue Feb 10, 2015 · 10 comments
Closed

Distance not appearing #28

andyharris opened this issue Feb 10, 2015 · 10 comments

Comments

@andyharris
Copy link

Hi there - I'm working on a "Find your nearest store" and for some reason it isn't returning distances. You can see a working example at http://lnsdev.pepperdigital.com/results/?q=evesham. The code I'm using is below (based on your example at https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Search-by-Proximity):

{% set query = craft.request.getParam('q') %}

{% set params = {
    address: query,
    distance: 200
} %}

{% set options = {
    id: 'map', 
    width: '400px', 
    height: '300px',
    clustering: true
} %}

{{ craft.googleMaps.map(options) }}

<ul class="search-results">
{% set entries = craft.entries.section('store').map(params).order('map_distance asc') %}
{% for entry in entries %}
    <li>
        <h3>{{ entry.title }}</h3>
        {{ craft.googleMaps.data('map', entry.map) }}
        {% for marker in entry.map.markers() %}
            <p>Distance - {{ marker.distance }}</p>
            {{ marker | inspect }}
        {% endfor %}
    </li>
{% endfor %}
</ul>
@objectivehtml
Copy link
Owner

I know it's been a couple weeks since you posted this, but just had a chance to fix this. Download the latest build in the master branch and this should be fixed now.

@andyharris
Copy link
Author

How strange, I was literally just looking at this again as you replied.

I'm getting this lot http://lnsdev.pepperdigital.com/results/?q=evesham%2C+wr11 - all I did was to upload the folder over the top of the old folder, would it be preferable to reinstall it?

@objectivehtml
Copy link
Owner

Ah, right this is my mistake. So previously the distances getting prefixed with your map's handle, ie map_distance. I really didn't like this behavior but I forgot to button up the changes. You can use "distance" for now, that will work. I am going to add a new option so you that you can define this value, and will default to "distance". Kinda complicated as to why this has to be this way, but it's necessary. I will get this fixed.

@andyharris
Copy link
Author

Got it, that appears to be working fine now - cheers Justin.

@sl8r
Copy link

sl8r commented Mar 16, 2015

Hi - I understood the above to say that we could use "distance." When I do, I get an internal server error:

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

{% set query = craft.request.getParam('q') %}

{% set params = {
    address: query,
    distance: 200
} %}

<h1>Search Results</h1>

{% set options = {
    id: 'map', 
    width: '400px', 
    height: '300px'
} %}

{{ craft.googleMaps.map(options) }}

<ul class="search-results">

{% set entries = craft.entries.section('retailers').map(params).order('distance asc').limit(2) %}

{% for entry in entries %}
    <li>{{ entry.title }} - {{ entry.retailerZip }}</li>
{% endfor %}
</ul>

I am using 0.8.3. Any thoughts on why it's not working?

Than you in advance.

@objectivehtml
Copy link
Owner

Did you download the latest master branch? I am in the process of updating this a bit but this should work with the code in the master branch.

@sl8r
Copy link

sl8r commented Mar 18, 2015

Yes, I did. Andy was also nice enough to share his copy, so I tried it just in case it was different. Both resulted in the same distance error. It's working on his end, but not mine, so I'm not sure how to isolate what the problem is. Andy and I are using the exact same template code, so we know that's not the issue.

Very puzzling. I've tried uninstalling and reinstalling. I should probably test this on a fresh install.

Running Craft Pro 2.3.2636 w/ Google Maps for Craft 0.8.3 (only plugin installed)

@objectivehtml
Copy link
Owner

Do you get this error when you visit the template url with a ?q=Some+Location added to the URL?

@objectivehtml
Copy link
Owner

I was able to duplicate this locally, but only when the 'q' variable did not exist. Currently, it's up to you to implement logic in your template to check to see if that variable exists, and if so use it to calculate the distance. I am open to suggestions on how to improve this to make it more automated, but I am almost certain that is causing the issue.

@mdxprograms
Copy link

This worked for me:
#47 (comment)

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

4 participants