Craft 5 - query with location
Description
I try to query some entries by lat/lng My Field handle is "addressCoordinates"
{% set haendler = craft.entries.section("haendler").addressCoordinates({
location: {
lat: 52.3073549,
lng: 8.6699708
},
radius: 50,
unit: 'km'
}).orderBy('distance asc').all() %}
Output is:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'order clause'
The SQL being executed was: SELECT `elements`.`id`, `elements`.`canonicalId`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateLastMerged`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id` AS `siteSettingsId`, `elements_sites`.`siteId`, `elements_sites`.`title`, `elements_sites`.`slug`, `elements_sites`.`uri`, `elements_sites`.`content`, `elements_sites`.`enabled` AS `enabledForSite`, `entries`.`sectionId`, `entries`.`fieldId`, `entries`.`primaryOwnerId`, `entries`.`typeId`, `entries`.`postDate`, `entries`.`expiryDate`
FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `siteSettingsId`
FROM `elements` `elements`
INNER JOIN `entries` `entries` ON `entries`.`id` = `elements`.`id`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
WHERE (`entries`.`sectionId`=10) AND (`elements_sites`.`siteId`=1) AND ((`elements_sites`.`content`->>'$.\"5691a8fb-651e-437b-b392-e568ca1955d2\"') IN (50, 'km')) AND (((`elements`.`enabled`=TRUE) AND (`elements_sites`.`enabled`=TRUE)) AND (`entries`.`postDate` <= '2024-06-07 09:31:59') AND ((`entries`.`expiryDate` IS NULL) OR (`entries`.`expiryDate` > '2024-06-07 09:31:59'))) AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId` IS NULL)
ORDER BY `distance`) `subquery`
INNER JOIN `elements` `elements` ON `elements`.`id` = `subquery`.`elementsId`
INNER JOIN `elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`siteSettingsId`
INNER JOIN `entries` `entries` ON `entries`.`id` = `subquery`.`elementsId`
ORDER BY `distance`
Error Info: Array
(
[0] => 42S22
[1] => 1054
[2] => Unknown column 'distance' in 'order clause'
)
Steps to reproduce
- Craft 5
- Query entries by lat/lng
Additional info
- Craft version: 5.1.8
- Maps version: 5.0.0
- PHP version: 8.3
- Database driver & version: MySQL 8.1.0
- Other Plugins: ether/seo, craft commerce, feed-me
I am having this issue as well. Is there any progress with that or any temporary solution anyone has come up with?
Same issue here. Any update on this?
any progress with this one? May not be any help, but I'm having a similar issue with the plugin on craft 5 where the query wont return any data. Only way I can get anything out of it is using crafts search syntax. Eg:
{% set retailers = craft.entries.section('retailers').mapAddress({
location: "london",
radius: 20,
unit: 'mi',
}).all %}
returns nothing, but
{% set retailers = craft.entries.section('retailers').mapAddress({
location: "*london*",
radius: 20,
unit: 'mi',
}).all %}
will return all entries with the word 'london' in it. Not particularly helpful in my instance, but may do the job if anyone is just looking to do a simple search by keyword on the map
Any news on that topic? Still having the same problem
I've had no updates. Our client has agreed to keep the map with its reduced functionality for now & we'll likely move to using a different plugin. I can't see that ether are responding to any issues so I'm starting to think simplemap has been abandoned
The same issue here! A quick fix would be nice @Tam - can't upgrade to Craft 5 because my client site need the search by location feature.
Hello folks,
I contacted Ether Creative directly by e-mail and received the following reply:
Hi Jan,
It’s still actively mantained and we’re working on a fix which we hope to release soon.
All the best Alex
So we have to wait a little bit. Thanks to Ether Creative for this excellent plugin 🙏🏼
Ether Creative please give us a feedback!
See my latest findings. Any update Ether?
Also experiencing this since upgrading to Craft 5. Searching by location and distance sort order is a core feature to our product so fingers crossed for an update soon 🤞
For those who are working with google maps api. There seems to be an issue with the referrer restrictions. If you add an restriction for websites, the plugin doesn't work anymore. If you remove the all referrer restrictions, it works like before. I don't know how the plugin calls the API, but maybe we can look into this.