Yes, it is precisely that geography and spatial methods are good. Here is a quick example:
DECLARE @Restaurant TABLE ( Name nvarchar(50), Location geography, DeliveryRadiusMetres int ); INSERT @Restaurant VALUES -- long lat ('Dominos','POINT(-0.109339 51.532835)',2000 ), ('Pizza Hut','POINT(-0.102961 51.541157)',2000 );
Note that here, to build geography values, I use an implicit string conversion that invokes geography::Parse behind the scenes.
DECLARE @MyLocation geography = 'POINT(-0.115063 51.550231)'; SELECT Name FROM @Restaurant R WHERE R.Location.STDistance(@MyLocation) <= R.DeliveryRadiusMetres ;
source share