objectivehtml / Google-Maps-for-Craft

The complete geolocation toolkit for Craft CMS.
Other
94 stars 20 forks source link

Distance not appearing #28

Closed andyharris closed 8 years ago

andyharris commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

sl8r commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

objectivehtml commented 9 years ago

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 commented 8 years ago

This worked for me: https://github.com/objectivehtml/Google-Maps-for-Craft/issues/47#issuecomment-157254897