English 中文(简体)
2. 找到下一个最接近地点的地方
原标题:Get the id of the next closest location

我有一份申请,用户可以选择一个地点,将其与几个利益点相距。

当我找回这些距离时,我也希望从每个POI最接近和最远的地方取回身份证。 例如。 如果我们有10个地点,其中每一个地点都比我回来的某个POI更远: The name of the POI, The gap from that POI, The ID of the next nearst place, and the ID of the next furth place. 计算结果的一个例子是:足球场,1.5、24、784(由于我们所看到的地点距足球场1.5英里,位置24是下一个最接近点,784是下一个最远的地方。

说明:我们所看到的地点有可能是最接近或最远的地方,在这种情况下,我们需要将1号归还给下一个最接近或最接近的地点,以便让前线知道,我们可能不会变得更加接近或进一步。

我想尽可能在一份发言中这样做。 我设立了一个职能,将计算两点之间的距离,并在申请前后使用:

 create FUNCTION [dbo].[fnc_calc_distance]
(
    @lat1 as float,
    @lng1 as float,
    @lat2 as float,
    @lng2 as float
)
RETURNS float
AS
BEGIN
    declare @result as float    
    select @result = (3959*acos(cos(radians(@lat2))*cos(radians(@lat1))*cos(radians(@lng1)-radians(@lng2))+sin(radians(@lat2))*sin(radians(@lat1))))
    RETURN @result
END

样本表结构/数据如下:

CREATE TABLE tbl_locations(
    [houseID] [int] NOT NULL,
    [lat] [decimal](14, 10) not NULL,
    [lng] [decimal](14, 10) not NULL) 

insert into tbl_locations
    values (1, 54.9834400000, -1.6314250000)
insert into tbl_locations
    values (2, 54.9860420000, -1.5912680000)
insert into tbl_locations
    values (3, 54.9882050000, -1.5707710000)

CREATE TABLE tbl_poi(
    [ID] [int] NOT NULL,
    [name] [varchar](32) NOT NULL,
    [lat] [decimal](14, 10) NOT NULL,
    [lng] [decimal](14, 10) NOT NULL)

insert into tbl_poi
    values (1,  Football Ground , 54.9752430000, -1.6219210000)
insert into tbl_poi
    values (1,  Train Station , 54.9898610000, -1.6047600000)

I m2008年使用服务器。

提前感谢。

Chris

问题回答

我处理此事的方式是归还与巴勒斯坦民族权力机构有关的一批定购地点。 根据您的申请,你可以把这局限于第一个N项目或X距离之内。 如果将数量限制在一定数目之内,那么了解有多少项目需要知道你是否应当表明有更多的项目可供使用。 不幸的是,我不知道如何在单一询问中这样做。

我的口号是,在用户选择的网页上储存所选兴趣点的名称、编号、编号、编号和时间。 然后,我将把这些反馈给服务器,并在第二次查询中加以使用(以获得定购清单)。 如有必要,我进行第三次问询,以找出其中的物品总数(第(*)项),看我是否需要提供“更多项目”链接。

第二个问题可能像:

 select TOP 10 t.id, t.name, t.lat, t.long, t.distance
 from (select id, name, lat, long, fnc_calc_distance(lat,@house_lat,long,@house_long) as distance
       from tbl_poi) t
 order by t.distance desc

您在选定的用户选择参数中通过。





相关问题
Performance impact of indexed view in MS SQL Server 2008

Does anyone have experience with using indexed view in MS SQL Server 2008? I am trying to find out how does indexed view affect performance of insert / update statements, that are adding / updating ...

Lock Escalation - What s happening here?

While altering a table (removing a column) in SQL Server 2008, I clicked the Generate Change Script button and I noticed that the change script it generated drops the column, says "go" and then runs ...

Round to nearest 5 in SQL Server

I have a Money column in my SQL Server 2008 table. In my below query how can I round it to nearest 5$ select FineAmount from tickets Thanks

热门标签