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

  • Home
  • SEARCH
  • 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 8226757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:53:13+00:00 2026-06-07T15:53:13+00:00

Possible Duplicate: Fastest Way to Find Distance Between Two Lat/Long Points I have locations

  • 0

Possible Duplicate:
Fastest Way to Find Distance Between Two Lat/Long Points

I have locations table which consists of all the locations with their latitude and longitude values. I am getting the particular locations lat. logn. and radius. Now, I want to find all the reocords within this radius and for that given lat. and long. values. I am using the following query. But I am not sure whether it gives me the correct results or not.

From given lat and long I am finding out lat.min and max as –

$lng_min = $longitude - $radius / abs(cos(deg2rad($latitude)) * 69);
$lng_max = $longitude + $radius / abs(cos(deg2rad($latitude)) * 69);
$lat_min = $latitude - ($radius / 69);
$lat_max = $latitude + ($radius / 69);

and then use the following query –

SELECT * FROM  merchant_branches,locations 
where locations."coorX" BETWEEN $lng_min AND $lng_max 
AND  
locations."coorY" BETWEEN $lat_min AND $lat_max 
and merchant_branches.location_id = locations.id

where location id is the foreign key in merchant_brach table.

I am confused about the results I am getting. Plz help me.

  • 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-06-07T15:53:15+00:00Added an answer on June 7, 2026 at 3:53 pm

    You have to use something like this to get the nearest results to a given location

    $query = sprintf(
             "SELECT foo,
                      6371 * ACOS( Cos(RADIANS(lat)) * COS(RADIANS(%f))
                          * COS(RADIANS(%f) - RADIANS(lng)) + SIN(RADIANS(lat))
                          * SIN(RADIANS(%f)) ) * 1000 AS distance
                FROM `%s`
            ORDER BY distance",
            $lat, $lag, $lng, $table
        );
    

    You have to set $lat, $lng and $table according to your table structure and maybe set a limit to the result.

    You get a detailed explantation here Geo Distance Search with MySQL.

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

Sidebar

Related Questions

Possible Duplicate: Fastest way to get range complement I have a sorted array of
Possible Duplicate: Compute fast log base 2 ceiling What is the fastest possible way
Possible Duplicate: Fastest way to list all primes below N in python Although I
Possible Duplicate: array_push() vs. $array[] = … Which is fastest? Is it better to
Possible Duplicate: array_push() vs. $array[] = … Which is fastest? Is it better to
I have a table with two fields, and i need to duplicate one field
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: Split A4 PDF page into two A5 and back again I have
Possible Duplicate: Fastest way to determine if an integer's square root is an integer
Possible Duplicate: Fastest way to retrieve a <title> in PHP Suppose there is a

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.