objectivehtml / Google-Maps-for-Craft

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

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

Closed rylanb closed 8 years ago

rylanb commented 9 years ago

Hello, I think this is something to do with how I've set this up, but I have the latest version from master (0.8.2 as best I can tell?) and am getting this error.

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

I'm trying to use the search by proximity feature: https://github.com/objectivehtml/Google-Maps-for-Craft/wiki/Search-by-Proximity

This is my lookup and the rest of the code looks the same. {% set entries = craft.entries.section('storeLocations').level(2).map(params).order('map_distance asc') %} {% set entries = craft.entries.section('storeLocations').level(2).map(params).order('distance asc') %} {% set entries = craft.entries.section('storeLocations').map(params).order('map_distance asc') %} {% set entries = craft.entries.section('storeLocations').map(params).order('distance asc') %}

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

  <ul class="search-results">
  {% for entry in entries %}
      <li>
          <h4><a href="{{ entry.url }}">{{ entry.title }}</a></h4>

          {{ craft.googleMaps.data('map', entry.googleMapField) }}

          {% for marker in entry.googleMapField.markers() %}

              <p>
                  <b>{{ marker.title }} - {{ marker.distance }}</b> <br>
              </p>

          {% endfor %}
      </li>
  {% endfor %}

I've read all through the docs, but maybe missed something. This commit seems to indicate there should be a distance field or ability to set that, but I'm confused what that means and if its some sort of setup process I missed? https://github.com/objectivehtml/Google-Maps-for-Craft/commit/77a5ff8f04b5192a564a645ca21c2c354084f001 ?

Thanks for any help at all. I'm stumped!

rylanb commented 9 years ago

Damnit! "Note, when you want to sort by the proximity you must use the following format yourMapField_distance. When the query is built, the field name is prepended to the distance column."

Too late a night writing code. Nvm me.

rylanb commented 9 years ago

Well, "Column not found: 1054 Unknown column 'googleMapField_distance' in 'order clause". What am I doing wrong then? I prepended and no dice...

{% set entries = craft.entries.section('storeLocations').level(2).map(params).order('googleMapField_distance asc') %}

googleMapField is the handle for the Google Map I added to the Store Location fields which go in the Store Locations section. I'm stumped. Its late.

kblizeck commented 8 years ago

I'm getting the same error - any updates here?

Column not found: 1054 Unknown column 'distance' in 'order clause'.

Also doesn't work if I append my googleMap field to distance :: Column not found: 1054 Unknown column 'googleMap_distance' in 'order clause'.

mdxprograms commented 8 years ago

I have found a fix for distance. Hopefully this helps someone down the road. I originally used zip codes in comparison and was unable to get distance to work. Even after attempting to use street addresses and cities I was still unsuccessful. However, when I used lat/lng for both addresses it worked like a charm. I used the geocode function to get the lat/lng from zipcodes and then did the proximity example to get the distance associated between two endpoints.

objectivehtml commented 8 years ago

Sorry for the lack of replies guy. Was off work most of last year due to some serious health and personal issues. I'll try to address the problems here in case people are still wondering or having issues.

First off, I changed some code in the last major release and didn't update the wiki so that's likely causing confusing. Now, distance is the default value that is used, and there is a parameter to override. No more should you use the mapField_distance value. This format is obsolete at this point.

Here is another thread where I posted some additional remarks and possible fixes. Im going to close this thread, but if anyone else has any questions related to this issue please feel free to post them here.

https://github.com/objectivehtml/Google-Maps-for-Craft/issues/48