Get all records from MySQL database that are within Google Maps .getBounds?

前端 未结 10 1033
既然无缘
既然无缘 2020-12-02 12:53

Ok I have a database with about 1800 rows, each has a column lat and long, what I am trying to do, it query against Google Maps V3 .getBounds

10条回答
  •  一整个雨季
    2020-12-02 13:02

    We can find result between Maps.getBounds northEast and southWest latitude and northEast and southWest longitude using below query.

    Search query should be between northEast.latitude AND southWest.latitude AND northEast.longitude AND southWest.longitude

    $nelat=$_GET['nelat']-0.5;
    $nelng=$_GET['nelng']-0.5;
    $swlat=$_GET['swlat']-0.5;
    $swlng=$_GET['swlng']-0.5;
    
    $sql ="SELECT * FROM tablename where (CASE WHEN ".$nelat." < ".$swlat."
        THEN s.latitude BETWEEN ".$nelat." AND ".$swlat."
        ELSE s.latitude BETWEEN ".$swlat." AND ".$nelat."
    END) 
    AND
    (CASE WHEN ".$nelng." < ".$swlng."
            THEN s.longitude BETWEEN ".$nelng." AND ".$swlng."
            ELSE s.longitude BETWEEN ".$swlng." AND ".$nelng."
    END)";
    

提交回复
热议问题