Rails 앱의 JSON 데이터를 jQuery를 사용하여 Google지도에 표시하는 데 문제가 있습니다. 내 map.js 파일에서 다음jQuery와 Rails를 사용하여 Google지도에 데이터 표시
class PlacesController < ApplicationController
respond_to :html, :xml, :json
# GET /places
# GET /places.xml
# GET /places.json
def index
@places = Place.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @places }
format.xml { render :xml => @places }
end
end
: 그리고 내 컨트롤러에서
$(document).ready(function(){
if (GBrowserIsCompatible()) {
var map = new google.maps.Map2($("#map").get(0));
var burnsvilleMN = new GLatLng(44.797916,-93.278046);
map.setCenter(burnsvilleMN, 8);
map.setUIToDefault();
$.getJSON("/places", function(json) {
if (json.Places.length > 0) {
for (i=0; i<json.Places.length; i++) {
var place = json.Places[i];
addLocation(place);
}
}
});
function addLocation(place) {
var point = new GLatLng(place.lat, place.lng);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
});
$(window).unload(function() { GUnload(); });
내가 this tutorial에서 내 코드에 적응 한 -지도 잘하지만 현재 내 마커가 하나도 없다 (추가 표시 손). 나는 레일즈 3 베타 3과 루비 1.9.1을 사용하고 있습니다. JSON 출력은 괜찮아 보입니다 .-places.json의 데이터에 액세스 할 수 있습니다. 어떤 도움이라도 대단히 감사 할 것입니다 - 미리 감사드립니다!
네,하지만 슬프게도 기쁨이 없습니다! 또한 "/places.js"와 함께 컨트롤러에 format.js {: render => @places}를 시도했습니다 ... – Budgie