gpt4 book ai didi

Mysql2::Error:...在地理编码器 gem 中调用 `near` 时

转载 作者:行者123 更新时间:2023-11-29 21:02:57 25 4
gpt4 key购买 nike

所以我有一个服务列表,所有服务都使用 geogoder gem 进行了地理编码。

调用 Service.near("London") 抛出

ActiveRecord::StatementInvalid: Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

Service.near("伦敦").to_sql

给出

SELECT services.*, MOD(CAST((ATAN2( ((services.longitude - -4.8824474) / 57.2957795), 
((services.latitude - 36.510071) / 57.2957795)) * 57.2957795) + 360 AS decimal), 360) AS bearing
FROM `services`
WHERE (services.latitude BETWEEN 36.220607433778305 AND 36.7995345662217
AND services.longitude BETWEEN -5.242587667147616 AND -4.522307132852385
AND () BETWEEN 0.0 AND 20)
ORDER BY distance ASC

distance_ Between工作没有问题。

谁能告诉我我做错了什么?

提前致谢

最佳答案

您必须发送正确的参数,以便 Geocoder gem 合成工作 SQL。

gem documentation ,虽然确实没有明确说明,但您需要完全指定所有参数

nearbys = Place.near("Omaha, NE", 50,:order => "distance")

一般

   nearbys = Model.near("Gecodeable address string", N (range constant), order: parameter)

对于您的情况,我建议尝试以下操作,看看是否可以解决 MySQL 错误

@result = Service.near("London, UK", YOUR_DISTANCE_CONSTANT, order: false)

我不知道这有多大帮助,但这是为我的模型之一生成的 SQL .near。我正在传递地理坐标并测试“事件”标志:

[1m[36mAnimalRescue负载(0.0ms)[0m[1mSELECTanimal_rescues.*, 3958.755864232 * 2 * ASIN(SQRT(POWER(SIN((30.326374 -animal_rescues.latitude)) * PI()/180/2 ), 2) + COS(30.326374 * PI()/180) * COS(animal_rescues.latitude * PI()/180) * POWER(SIN((-97.771258 - Animal_rescues.longitude) * PI()/180/2) , 2))) AS 距离, MOD(CAST((ATAN2( ((animal_rescues.longitude - -97.771258)/57.2957795), ((animal_rescues.latitude - 30.326374)/57.2957795)) * 57.2957795) + 360 AS 十进制), 360 ) AS 轴承 FROM "animal_rescues"WHERE "animal_rescues"."active_listing"= 't' AND (animal_rescues.latitude BETWEEN 29.77639322417878 AND 30.876354775821223 AND Animal_rescues.longitude BETWEEN -98.40842692015944 AND -97.13408907984056 AND (3958.755864232 * 2 * ASIN(SQRT(电源( SIN((30.326374 - 动物救援.纬度) * PI()/180/2), 2) + COS(30.326374 * PI()/180) * COS(动物救援.纬度 * PI()/180) * POWER(SIN( (-97.771258 - Animal_rescues.longitude) * PI()/180/2), 2)))) 0.0 和 38 之间) ORDER BY payment_item_count + dropoff_item_count DESC LIMIT 3[0m

关于Mysql2::Error:...在地理编码器 gem 中调用 `near` 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37058748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com