我正在尝试使用 DBIx::Class 进行周边搜索,但到目前为止还没有成功。
我想生成的 SQL 如下所示:
SELECT
zip,
6371 * ACos( Cos(RADIANS(Lat)) * Cos(RADIANS(USERLAT)) * Cos(RADIANS(USERLNG) - RADIANS(Lng)) + Sin(RADIANS(Lat)) * Sin(RADIANS(USERLAT)) ) AS Distance
FROM
geopc
WHERE
6371 * ACos( Cos(RADIANS(Lat)) * Cos(RADIANS(USERLAT)) * Cos(RADIANS(USERLNG) - RADIANS(Lng)) + Sin(RADIANS(Lat)) * Sin(RADIANS(USERLAT)) ) <= DISTANCE
ORDER BY
Distance
其中 USERLAT、USERLNG 和 DISTANCE 应该是变量,它们将通过 Webrequest 进入。
我的 DBIx::Class 结果:
use utf8;
package MyApp::Models::Schema::Result::Geopc;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("geopc");
__PACKAGE__->add_columns(
"id",
{ data_type => "bigint", is_nullable => 0, is_auto_increment => 1 },
"country",
{ data_type => "varchar", is_nullable => 0, size => 2 },
"language",
{ data_type => "varchar", is_nullable => 0, size => 2 },
"iso2",
{ data_type => "varchar", is_nullable => 0, size => 6 },
"region1",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"region2",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"region3",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"region4",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"zip",
{ data_type => "varchar", is_nullable => 0, size => 10 },
"city",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"area1",
{ data_type => "varchar", is_nullable => 0, size => 80 },
"area2",
{ data_type => "varchar", is_nullable => 0, size => 80 },
"lat",
{ data_type => "double precision", is_nullable => 0 },
"lng",
{ data_type => "double precision", is_nullable => 0 },
"tz",
{ data_type => "varchar", is_nullable => 0, size => 30 },
"utc",
{ data_type => "varchar", is_nullable => 0, size => 10 },
"dst",
{ data_type => "varchar", is_nullable => 0, size => 1 },
);
__PACKAGE__->set_primary_key('id');
我用谷歌搜索,但没有找到处理这个问题的好方法。任何帮助将不胜感激。
我正在使用 MySQL ...