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 6984407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:32:43+00:00 2026-05-27T18:32:43+00:00

I send these paramaters my script : Latitude : 41.0186 Longitude : 28.964701 (it

  • 0

I send these paramaters my script : Latitude : 41.0186 Longitude : 28.964701 (it is sample). i want to find nearest location’s name. how to do this? (query’s where code’s must be changed)

Sql Query :

   SELECT  Name FROM Location 
   WHERE Latitude = 41.0186 AND longitude= 28.964701

Location table likes this: (in real, this is huge table)

Latitude         longitude          Name
41.0200500000   40.5234490000        a
41.0185714000   37.0975924000        b
41.0184913000   34.0373739000        c
41.0166667000   39.5833333000        d
41.0166667000   28.9333333000        e
  • 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-27T18:32:44+00:00Added an answer on May 27, 2026 at 6:32 pm

    Use this function

    CREATE FUNCTION dbo.DictanceKM(@lat1 FLOAT, @lat2 FLOAT, @lon1 FLOAT, @lon2 FLOAT)
    RETURNS FLOAT 
    AS
    BEGIN
    
        RETURN ACOS(SIN(PI()*@lat1/180.0)*SIN(PI()*@lat2/180.0)+COS(PI()*@lat1/180.0)*COS(PI()*@lat2/180.0)*COS(PI()*@lon2/180.0-PI()*@lon1/180.0))*6371
    END
    

    You may order by this function, BUT on large datasets it will be very slow, so try to prefilter the recordset

    UPD:

    Using @chopikadze’s test data:

    declare @lat float, @lng float
    select @lat = 41.0186, @lng = 28.964701
    
    declare @Location table(Latitude float, Longtitude float, Name nvarchar(50))
    insert into @Location(Latitude, Longtitude, Name) values (41.0200500000, 40.5234490000, 'a')
    insert into @Location(Latitude, Longtitude, Name) values (41.0185714000, 37.0975924000, 'b')
    insert into @Location(Latitude, Longtitude, Name) values (41.0184913000, 34.0373739000, 'c')
    insert into @Location(Latitude, Longtitude, Name) values (41.0166667000, 39.5833333000, 'd')
    insert into @Location(Latitude, Longtitude, Name) values (41.0166667000, 28.9333333000, 'e')
    
    SELECT ABS(dbo.DictanceKM(@lat, Latitude, @lng, Longtitude)) DistanceKm, * FROM @Location
    ORDER BY ABS(dbo.DictanceKM(@lat, Latitude, @lng, Longtitude))
    

    Assuming that the Earth is NOT a geoid, but the round ball, if you need under 1m exact formula – I can find it, don’t have it with me

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a stack of messages in database table. i want to send these
Some of my data are 64-bit integers. I would like to send these to
Either of these options would be fabulous: Send a bitmap image of the stage's
I have a JavaScript script: $(#feedbacksubmit).click(function() { if($(#frmfeedback).valid()) { var tname = $(#name).val(); var
Hi I've written a Python script to send a simple message. The script works
I have 5 parameters and I want to send them to the method: public
I'm using the PHP Pear Mail_Mime library to send email. In my script, I
I'm trying to send a POST request from an external Ruby script to a
I want to try to use a command line script with my python application.
I want a PHP to be able to send 1 of 3 images, depending

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.