未捕获的TypeError:pos.apply不是showtooltip()方法中的函数

时间:2016-01-01 11:58:41

标签: javascript jquery google-maps google-maps-api-2

jQuery(document).ready(function($) {
    var currentMap;var lat;var log;var latlongarray;var latitude;
    var longitude;var count = 0;var name;var number;var country;
    var maps;var address;var marker;var batch = [];


showTooltip = function(marker) {
    tooltip.innerHTML = marker.tooltip;
    var point = currentMap.getCurrentMapType().getProjection()
               .fromLatLngToPixel(currentMap.fromDivPixelToLatLng(
                new GPoint(0, 0),true),currentMap.getZoom());
    var offset = currentMap.getCurrentMapType().getProjection()
                 .fromLatLngToPixel(marker.getPoint(),
                                            currentMap.getZoom());
    var anchor = marker.getIcon().iconAnchor;
    var width = marker.getIcon().iconSize.width;
    var height = tooltip.clientHeight;
    var pos = new GControlPosition(G_ANCHOR_TOP_LEFT,
                       new GSize(offset.x - point.x - anchor.x + width,
                            offset.y - point.y - anchor.y - width));
    pos.apply(tooltip);
    tooltip.style.visibility = "visible";
}
initialize = function() {var tim = (new Date).getTime();
 var provNum = $("input[name='providerNumber']").val();        
$.getJSON('newmap.do?t=' + tim+ '&providerNumber='+ provNum,
        function(data) {$.each(data,function(i,item) {
                    address = item.name + item.address;
                    name = item.name;
                    latitude = item.lattitude;
                    longitude = item.longitude;
                    number = item.number;
                    var icon = new GIcon();
                    icon.image = "images/pin.png";
                    icon.iconAnchor = new GPoint(16,16);
                    icon.infoWindowAnchor = new GPoint(16,0);
                    icon.iconSize = new GSize(32,32);
                    icon.shadowSize = new GSize(59,32);         
                    marker = new GMarker(new GLatLng(item.lattitude,
                                     item.longitude),{
                                                    draggable : true,
                                                    icon : icon
                                        });
                    lat = item.lattitude;
                    log = item.longitude;
                    marker.disableDragging();
                    batch.push(marker);
                    marker.tooltip = "<div class='tooltip'>"+item.name+
                                '<br>'+ item.number+'<br>BEDS:'+ item.bed
                                + '<br>DSH: '+ item.dsh+ "</div>";

                    GEvent.addListener(marker,"mouseover",function() {
                                    showTooltip(marker);
                                    });
                    GEvent.addListener(marker,"mouseout",function() {
                                    tooltip.style.visibility = "hidden";
                        }); 
                    GEvent.addListener(marker,"mouseout",function() {
                                    tooltip.style.visibility = "hidden";
                        });             
                    });
   if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map-c"));
        map.setCenter(new GLatLng(lat,log),11);
        tooltip = document.createElement("div");
        map.getPane(G_MAP_FLOAT_PANE).appendChild(tooltip);
        tooltip.style.visibility = "hidden";
        map.setUIToDefault();
        mgr = new MarkerManager(map);
        mgr.addMarkers(batch,2);
        mgr.refresh();
        currentMap = map;
     }

     });
   });
}
if (jQuery.browser.safari&& document.readyState != "complete") {
            initialize();   
}
});

这是我的代码..这里我从sql获得了经验和在谷歌地图中添加标记。现在我试图为每个标记添加信息框 但是我得到了一个错误  &#34;未捕获的TypeError:pos.apply不是函数&#34; 在线     &#34; pos.apply(提示);&#34; 有谁知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

.apply是Function.prototype的一部分,在普通对象中不可用。

让我告诉你,你在这里做了什么。

var obj = {i : 10}
obj.apply(this); //Uncaught TypeError: obj.apply is not a function

您正在从new GControlPosition创建一个对象并且在此对象上.apply不可用