IE会解析为GoogleMap解析数据的错误

时间:2011-03-09 12:04:32

标签: javascript internet-explorer google-maps

我添加了使用Google.API显示具有特定地理位置的元素的地图。在现代浏览器中,一切正常,但IE7 / 8一如既往地存在一些问题。当尝试使用每个元素的lat / long参数来居中地图时,我得到错误说明,'lat'在行var pos_lat = parseFloat(data_map[i]['lat']);中是“空的或不是对象”。使用相同的数据在适当的位置添加静止标记。有人有这种问题吗?

<script type='text/javascript'> 
    var map;   

    var mapStart = function(){
        if(GBrowserIsCompatible()){
            map = new GMap2(document.getElementById("map"));
            map.setCenter(new GLatLng(51.961869,19.134521),6);
            map.addControl(new GLargeMapControl());

            var icon1 = new GIcon();
            icon1.image = "/static/images/map_icon_1.png";
            icon1.iconSize = new GSize(36, 30);
            icon1.infoWindowAnchor = new GPoint(16,16);
            icon1.iconAnchor = new GPoint(16,16);
            var data_map = [{'url': '/bo/properties/property/7/', 'lat': '52.1898985', 'long': '20.8461914', 'name': 'asdfgh'},]       
            mapa.enableDoubleClickZoom();
            mapa.enableContinuousZoom();
            var bounds = new GLatLngBounds();
            var maxlng =0;
            var maxlat=0;
            var minlng=0;
            var minlat=0;
            var positions=0;
            var zoom = 0;
            for (var i=0; i < data_map.length; i++){
                var pos_lat = parseFloat(data_map[i]['lat']);
                var pos_lon = parseFloat(data_map[i]['long']);
                if(!isNaN(pos_lat) && !isNaN(pos_lon)){
                    positions = 1;
                    zoom++;
                    addMarker(pos_lat, pos_lon,{icon:icon1});
                    if (pos_lat < minlat || minlat==0){ minlat = pos_lat}
                    if (pos_lat > maxlat || maxlat==0){ maxlat = pos_lat}
                    if (pos_lon < minlng || minlng==0){minlng = pos_lon}
                        if (pos_lon > maxlng || maxlng==0){maxlng = pos_lon}
                    lat = minlat + (( maxlat - minlat)/2);
                    lng = minlng + (( maxlng - minlng)/2);
                    var allpoints = new GLatLng(lat,lng);
                    bounds.extend(allpoints);
                }
            }

            if(positions){
                if(zoom > 2){
                    mapa.setZoom(map.getBoundsZoomLevel(bounds)-2);
                }
                else{
                    map.setZoom(10);
                }
                map.setCenter(bounds.getCenter());            
            }
        }
    }

    var addMarker = function(lat, lon, options){
        point = new GLatLng(lat,lon);
        var marker = new GMarker(point, options);

        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(info_box_html);
        });

        map.addOverlay(marker);
    }

    $(document).ready(function(){
        mapStart();
    });   
    window.onunload = function (){ GUnload()};
</script>

1 个答案:

答案 0 :(得分:0)

var data_map = [{'url': '/bo/properties/property/7/', 'lat': '52.1898985', 'long': '20.8461914', 'name': 'asdfgh'},]

数组末尾有一个额外的逗号。 另请尝试使用data_map[i].lat代替data_map[i]['lat']