【发布时间】:2012-07-30 17:34:32
【问题描述】:
下午,
我很难理解这个问题。我有一个 MySQL 表,其中列出了英国邮政编码及其经度和纬度值。我希望能够在表格上进行搜索,以找到最接近给定长/纬度对的邮政编码。
我一直在尝试使用的查询是:
"SELECT id, outcode AS thecode, @la := MATCH(lat) AGAINST(?) AS score_lat, @ln := MATCH(lng) AGAINST(?) AS score_lng, @la + @ln AS score_total FROM postcodes ORDER BY score_total DESC LIMIT 10
然而,这只是返回看似随机的邮政编码,例如 Lat:55.775549 和 Long:-4.047556
Array
(
[0] => Array
(
[id] => 929
[thecode] => FK14
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[1] => Array
(
[id] => 2785
[thecode] => UB3
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[2] => Array
(
[id] => 993
[thecode] => G70
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[3] => Array
(
[id] => 2849
[thecode] => WC2B
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[4] => Array
(
[id] => 1057
[thecode] => GU29
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[5] => Array
(
[id] => 2913
[thecode] => WS13
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[6] => Array
(
[id] => 1121
[thecode] => HP20
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[7] => Array
(
[id] => 1185
[thecode] => IG6
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[8] => Array
(
[id] => 1249
[thecode] => IV25
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
[9] => Array
(
[id] => 1313
[thecode] => KA8
[score_lat] => 0
[score_lng] => 0
[score_total] => 0
)
)
数据库的架构是:
CREATE TABLE `postcodes` (
`id` int(11) NOT NULL auto_increment,
`outcode` varchar(4) NOT NULL,
`lat` varchar(20) NOT NULL,
`lng` varchar(20) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT KEY `lat` (`lat`),
FULLTEXT KEY `lng` (`lng`)
) ENGINE=MyISAM AUTO_INCREMENT=2975 DEFAULT CHARSET=latin1 AUTO_INCREMENT=2975 ;
希望有人能帮忙!如果您需要更多信息,请询问...
谢谢,
tip2tail
【问题讨论】:
-
您看过了吗:dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html 您的应用程序相当简单,因为它只是距离公式的基本应用,但您要问的是空间问题。您正在尝试匹配您实际提出的问题是距离问题的字符串。这种方法永远不会有效。
-
@hsanders 我不知道从哪里开始!你能提供任何建议或例子来说明我如何实现我需要的吗?谢谢tip2tail
标签: php mysql geolocation match