查找最近的经度和纬度Find Nearest Latitude and Longitude

2 个回复2

===============>>#1 票数：1

``````create table dbo.Hotels (
HotelID int identity not null,
constraint [PK_Hotels] primary key clustered (HotelID),
Longitude decimal(15, 12) not null,
Latitude decimal(14, 12) not null,
geo as geography::Point(Latitude, Longitude, 4326)
)

insert into dbo.Hotels
(Longitude, Latitude)
values
(-122.4167, 37.7833);
go

create procedure dbo.findHotels (@point geography, @distanceKM int = 15)
as
begin
--SRID 4326 measures disances in meters, so use that measure
declare @distanceM int = @distanceKM * 1000;

select HotelID, @point.STDistance(geo) as [DistanceInM]
from dbo.Hotels
where @point.STDistance(geo) <= @distanceM
order by @point.STDistance(geo);
end
go

declare @longitude decimal(15, 12) = -122.4168,
@latitude decimal(14, 12) = 37.7832;
declare @p geography = geography::Point(@latitude, @longitude, 4326);

exec dbo.findHotels @p, 15;
``````

===============>>#2 票数：0

``````SELECT * FROM Places WHERE
(Lat => 1.2393 AND Lat <= 1.5532) AND (Lon >= -1.8184 AND Lon <= 0.4221)
AND
acos(sin(1.3963) * sin(Lat) + cos(1.3963) * cos(Lat) * cos(Lon - (-0.6981))) <= 0.1570;
``````

2回复

2回复

1回复

1回复

2回复

1回复

5回复

1回复

1回复

1回复