0

In my table tblStore there are store some location latitude and longitude according to store address I want to get an exact store, as well as nearby function, means user enter any state, city, address or Pincode so they can check with data eg. Latitude Longitude column as gives nearby match data. So for that, I write a query as below. MY TABLE

 StoreName  StoreAddress    City    State          Pincode    Latitude   Longitude
 ABC          LAVBHANDI    RAIPUR    CHHATTISGARH 492001    21.23976180 81.68179490
 SDF           AIRPORT     AHMEDABAD GUJARAT      380003    21.06800900 70.49738180
 QWE           GORWA       VADODARA  GUJARAT      390023    22.32212250 73.16322990
 ZXC           MUGDALLA    SURAT     GUJARAT      395007    21.14517370 72.75489680
 HUI           MAHADEVPUR  BANGALORE KARNATAKA    560048    12.99703720 77.69443030
 TSM           YASHWANTPUR BANGALORE KARNATAKA    560055    13.01079010 77.55269750
 RRS           MAHADEVPUR  BANGALORE KARNATAKA    560048    12.99633780 77.69316240
 JJK           KEMPSCORNER MUMBAI    MAHARASHTRA  400036    18.96409600 72.80603600
 LLI           PAREL       MUMBAI    MAHARASHTRA  400013    18.99463540 72.82238490
 GT            SANTACRUZ   MUMBAI    MAHARASHTRA  400099    19.09108550 72.85647240
 SSS           MALAD       MUMBAI    MAHARASHTRA  400062    19.18504160 72.83411740
 GKO           GHATKOPAR   MUMBAI    MAHARASHTRA  400086    19.09987280 72.91395000

So my query is supposed I search store address like Andheri but my table no Address like Andheri so it checks in DB and returns to Andheri nearest location. I take Andheri location by using jquery I fetch latitude and longitude of Andheri location and pass to DB

MY SQL QUERY WAS :

declare @Latitude  decimal(18,8)= 19.113645
declare @Longitude  decimal(18,8)= 72.86973390000003
declare @latmin decimal(18,8) = @Latitude   -0.30;
declare @latmax decimal(18,8) = @Latitude   +0.30;
declare @longmin decimal(18,8) = @Longitude -0.30;
declare @longmax decimal(18,8) = @Longitude +0.30;


  select * from tblStore
  where  Latitude  between @latmin    and  @latmax
  and Longitude between @longmin and  @longmax 
  order by Latitude desc

it shows me all store location in Mumbai I want onlySantacruz and malad So how to set diameter for google location using SQL query.

Tushar
  • 182
  • 3
  • 19
  • Look into using the Haversine formula. It is well covered on Stack Overflow. – Tim Biegeleisen Jun 11 '18 at 09:27
  • @TimBiegeleisen https://stackoverflow.com/questions/39338167/sql-query-of-haversine-formula-in-sql-server this example – Tushar Jun 11 '18 at 09:54
  • i try Select StoreID,City,Latitude,Longitude, ( 3959 * acos( cos( radians(49.5284664) ) * cos( radians( 19.18504160 ) ) * cos( radians( 72.83411740 ) - radians(0.2537847 ) ) + sin( radians(49.5284664 ) ) * sin( radians( 19.18504160 ) ) ) ) AS distance FROM tblStore – Tushar Jun 11 '18 at 10:21
  • That looks on the right track. By the way, SQL Server probably also has geospatial packages that can help with this. But the query you wrote above is at least a start. – Tim Biegeleisen Jun 11 '18 at 10:24
  • But sir that query give me same distance – Tushar Jun 11 '18 at 10:34
  • I got some solution throw this reference https://www.youtube.com/watch?v=Qkz2PVATCqo – Tushar Jun 12 '18 at 07:32
  • Thank You @TimBiegeleisen for your refrance – Tushar Jun 12 '18 at 07:34

0 Answers0