У меня проблемы с получением данных JSON из моего приложения Rails для отображения на карте Google с помощью jQuery. В моем контроллере:
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
А потом в моем файле map.js:
$(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(); } );
Я адаптировал свой код из этого урока - карта отображается нормально, но ни один из моих маркеров отсутствует (добавлен вручную). Я использую Rails 3 beta 3 и Ruby 1.9.1. Вывод в JSON выглядит нормально - я могу получить доступ к данным в /places.json. Любая помощь будет высоко ценится - заранее спасибо!