0

gmaps4rails gemを使ってマップを自分のアプリに表示します。ユーザーが場所、半径、半径タイプを入力できる部分があります。gmaps4rails gemを使用してradius circleをリフレッシュするにはどうすればよいですか?

例:

location => Chicago, IL, 
within => 10, 
radius type => km(kilometer). 

私は、ユーザーが「更新レビュー」リンクをクリックすると、円のマーカーと半径を更新したいです。私は既に以下の構文を使用してマーカーを置き換えました:

function add_marker(location_served) { 
    var location = $(location_served).val(); 
    var geocoder; 

    geocoder = new google.maps.Geocoder(); 
    geocoder.geocode({ 
     'address': location 
    }, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      Gmaps4Rails.replace_markers([{ 
       "description": "", 
       "title": "", 
       "longitude": results[0].geometry.location.lng(), 
       "latitude": results[0].geometry.location.lat(), 
       "picture": "", 
       "width": "", 
       "height": "" 
      }]); 
     } else { 
      alert("The location you've entered is invalid"); 
     } 
    }); 
} 

しかし、円の半径を更新する方法についてはわかりません。 gmaps4rails.jsにはcreate_circleメソッドがありますが、そのメソッドを使用するときに渡すべきパラメータはわかりません。

サークルを動的に更新する方法を知っている人はいますか?

おかげ

答えて

0
function add_marker(location_served) { 
    var location = $(location_served).val(); 
    var geocoder; 

    geocoder = new google.maps.Geocoder(); 
    geocoder.geocode({ 
    'address': location 
    }, function(results, status) { 
    if (status == google.maps.GeocoderStatus.OK) { 
    Gmaps4Rails.replace_markers([{ 
     "longitude": results[0].geometry.location.lng(), 
     "latitude": results[0].geometry.location.lat() 
    }]); 

    //brute way to do 
    Gmaps4Rails.clear_circles(); 
    Gmaps4Rails.circles = [{"latitude": , "longitude": , "radius":}]; 
    Gmaps4Rails.create_circles(); 

    //soft way (if you only want to update radius) 
    Gmaps4Rails.circles[0].google_object.setRadius(number_here); //beware in the latest version of the gem I replaced google_object with serviceObject 

    } else { 
     alert("The location you've entered is invalid"); 
    } 
    }); 
} 
+0

あなたの答えをありがとう。 'Gmaps4Rails.circles = [{"latitude":-122.214897、 "経度":-122.214897、 "radius":10000}]を追加します。 Gmaps4Rails.create_circles(); '円はありません、参考、私はバージョン0.7.6を使用しています。あなたの次の答えをありがとう – fatimah

+0

奇妙なことに、既に存在しています。https://github.com/apneadiving/Google-Maps-for-Rails/blob/v0.7.6/public/javascripts/gmaps4rails.jsよくあることは何ですか? – apneadiving

+0

ええと、エラーメッセージはありません。しかし、サークルは現れなかった。 – fatimah

2

は、円は以下の回答で表示されない理由は、緯度/経度のためのタグです:

//brute way to do 
... 
Gmaps4Rails.circles = [{"latitude": , "longitude": , "radius":}]; 

はよる

Gmaps4Rails.circles = [{"lat": , "lng": , "radius":}]; 

であるべきto gmaps4rails.base.js line 165

関連する問題