Gmaps4Rails将标记附加到现有地图

时间:2014-09-05 14:05:50

标签: javascript google-maps gmaps4rails

我正在尝试将asynchonios加载到我已渲染的地图:

 handler = Gmaps.build('Google');
            handler.buildMap({ provider: {
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                styles: mapStyle_dark },
                internal: {
                    id: 'map'}}, function () {
                var json_array = $.getJSON("locations/async.json", function (data) {
                    return data;
                });
                var markers = handler.addMarkers(json_array);
                handler.fitMapToBounds();
                handler.getMap().setZoom(2);
            });

我的ajax响应如下:

[{"lat":48.21042800000001,"lng":16.3822238,"infowindow":{"id":"53a0a0012d289ec127000020","image":"veq3r13nbgn5qg9c7zqk","name":"Blended Shisha Lounge Bar","categories":[{"name":"Bars","slug":"bars","icon":"bars"}],"coordinates":[16.3822238,48.21042800000001]},"picture":{"anchor":[17,17],"url":"/assets/map/icons/categories/bars-38.png","width":38,"height":38}}]

但标记没有附加。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

取代:

var json_array = $.getJSON("locations/async.json", function (data) {
   return data;
});
var markers = handler.addMarkers(json_array);

使用:

$.getJSON("locations/async.json", function (json_array) {
   var markers = handler.addMarkers(json_array);
});