Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6916127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:33:44+00:00 2026-05-27T09:33:44+00:00

I want to show data based on latitude and longitude with specified radius. Example:

  • 0

I want to show data based on latitude and longitude with specified radius.

Example:

I have a record with latitude 55.0628 and longitude -162.3056 without specified state.

How can I show only records that within one state, using entity to linq?

If I have state Florida to show just records that within Florida.

Table Data

id            item             latitude                 longitude
1             townhome          55.0628                 -162.3056


Table postal codes

id               state                 city            latitude            longitude
1                alaska                Akutan          54.143              -165.7854
2                Alabama               Huntsville      34.7448             -86.6704
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:33:44+00:00Added an answer on May 27, 2026 at 9:33 am

    I would execute the query as close to the actual data as possible (which probably means circumventing LINQ and calling a stored procedure).

    Here is a SQL user defined function that I use to calculate the distance between two locations. It leverages the new geography functionality introduced in SQL Server 2008.

    CREATE FUNCTION [dbo].[GetDistanceBetween]
    (
        @Lat1 float,
        @Long1 float,
        @Lat2 float,
        @Long2 float
    )
    RETURNS float
    AS
    BEGIN
    
        DECLARE @RetVal float;
        SET @RetVal = ( SELECT geography::Point(@Lat1, @Long1, 4326).STDistance(geography::Point(@Lat2, @Long2, 4326)) / 1609.344 );
    
    RETURN @RetVal;
    
    END
    

    Function returns distance in miles and is very fast in my experience (this will obviously depend on how many comparisons you need to make).

    You could call it using something like:

    DECLARE @StartingLatitude FLOAT, @StartingLongitude FLOAT;
    DECLARE @MaxDistance FLOAT = 50;
    
    SELECT * FROM PostalCodes 
    WHERE dbo.GetDistanceBetween(@StartingLatitude, @StartingLongitude, latitude, longitude) <= @MaxDistance;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with many rows of data, and I want to show
I have a UIViewController based app and I want to changes data on view
I have a LINQ query that returns data and I want to filter based
I have a background worker running a long database task. i want to show
I want to show a custom image with some data in it while clicking
i want to show some data to the user the data maybe represented to
I have a Core Data-based iPhone app with a pre-populated read-only database. What protection
I have an app that performs some calculations based on data arriving on a
In my Windows based application(C#) i want to import excel sheet to show its
I have an iPhone app based on a tabBar and tableViews. I want the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.