2017-05-05 12 views
0

ホテルの緯度、経度、および場所を保存したテーブルがあります。私が実装したい機能は、緯度と経度で指定された点の近くにあるデータベースから取得したホテルを表示する必要があります。データベースに格納されている緯度と経度に近いホテルを取得する方法

コントローラ

 function check() 
     { 
     $this->load->model('hotel'); 
     $lat1=$this->input->post('lat'); 
     $lng1=$this->input->post('lng'); 
     $count['matched_data'] = $this->hotel->hoteldisplay($lat1,$lng1); 
     $checkdb =count($count['matched_data']); 
     } 
    Here is model: 
      function hoteldisplay($lat1,$lng1) 
      { 
      $this->db->select("landmark,(3959 * acos(cos(radians($lat1)) * 
      cos(radians(lat)) * cos(radians(longi) - rad`ians($lng1)+sin( 
      radians($lat1)) * sin(radians(lat)))) AS distance"); 
      $this->db->having('distance' <= 25);      
      $this->db->order_by('distance');      
      $this->db->limit(20, 0); 
      } 
+0

あなたのご質問はありますか? –

+0

あなたの質問は何ですか?あなたが使っているフレームワークは何ですか? –

+0

彼は@YazanWYusufというフォーマットに基づいてcodeigniterを使用していると思いますが、彼のコントローラーモデルが正しいと推測しています。マーカーのクライアントサイドAJAXイベント関数を作成したいのですが...マーカーが固定されているとき、長い応答を返し、マップを更新 –

答えて

0

あなたのSQLクエリで半正矢距離を適用する必要があります。これは、例です。

SELECT z.zip, 
     z.primary_city, 
     z.latitude, z.longitude, 
     p.distance_unit 
       * DEGREES(ACOS(COS(RADIANS(p.latpoint)) 
       * COS(RADIANS(z.latitude)) 
       * COS(RADIANS(p.longpoint) - RADIANS(z.longitude)) 
       + SIN(RADIANS(p.latpoint)) 
       * SIN(RADIANS(z.latitude)))) AS distance_in_km 
    FROM zip AS z 
    JOIN ( /* these are the query parameters */ 
     SELECT 42.81 AS latpoint, -70.81 AS longpoint, 
       50.0 AS radius,  111.045 AS distance_unit 
    ) AS p ON 1=1 
    WHERE z.latitude 
    BETWEEN p.latpoint - (p.radius/p.distance_unit) 
     AND p.latpoint + (p.radius/p.distance_unit) 
    AND z.longitude 
    BETWEEN p.longpoint - (p.radius/(p.distance_unit * COS(RADIANS(p.latpoint)))) 
     AND p.longpoint + (p.radius/(p.distance_unit * COS(RADIANS(p.latpoint)))) 
    ORDER BY distance_in_km 
LIMIT 15 

撮影からhereです。 Code Igniterについては、hereを参照してください。

関連する問題