How to find nearest location using latitude and longitude from SQL database?

前端 未结 7 1428
离开以前
离开以前 2020-11-30 17:41

I want to find a nearest location from following database table

Address                            Latitude                longitude 

Kathmandu 44600, Nepal          


        
相关标签:
7条回答
  • 2020-11-30 18:09

    The SQL have a problem. In table like:

    `ubicacion` (
      `id_ubicacion` INT(10) NOT NULL AUTO_INCREMENT ,
      `latitud` DOUBLE NOT NULL ,
      `longitud` DOUBLE NOT NULL ,
      PRIMARY KEY (`id_ubicacion`) )
    

    The id_ubicacion change when use:

    SELECT  `id_ubicacion` , ( 3959 * ACOS( COS( RADIANS( 9.053933 ) ) * COS( RADIANS( latitud ) ) * COS( RADIANS( longitud ) - RADIANS( - 79.421215 ) ) + SIN( RADIANS( 9.053933 ) ) * SIN( RADIANS( latitud ) ) ) ) AS distance
    FROM ubicacion
    HAVING distance <25
    ORDER BY distance
    LIMIT 0 , 20
    
    0 讨论(0)
提交回复
热议问题