0

gmaps4rails gem を使用して、Rails アプリでマップを表示します。ユーザーが位置、範囲内、および半径タイプを入力できる部分があります。

例:

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");
        }
    });
}

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

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

ありがとう

4

2 に答える 2

2

以下の回答で円が表示されない理由は、lat/lng のタグです。

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

する必要があります

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

gmaps4rails.base.js 165行目によると

于 2011-08-28T07:15:58.907 に答える
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");
    }
  });
}
于 2011-07-03T14:24:09.707 に答える