Safari JS语法错误:意外的标记'='

时间:2016-04-28 08:01:49

标签: javascript google-maps-api-3 safari

我使用谷歌地图构建商店定位器。它适用于每个浏览器,但Safari,我不知道为什么。 Safari抛出错误: SyntaxError:意外的标记'='。在参数声明之后预期为')'或','。

这是代码(我稍微简短一点):

    var marker = [];
var LatLng;
var infoWindow = new google.maps.InfoWindow();
var markerInfo = [];
var bounds = new google.maps.LatLngBounds();
var queryLatlng = new google.maps.LatLng(50.9683679, 10.7635554);
var zoom = 6;
var markers = [];
var mapOptions = {
    center: queryLatlng,
    zoom: zoom,
    scroll: false,
    scrollwheel: false,
    streetViewControl: false,
    mapTypeControl: true,
    mapTypeControlOptions: {
        position: google.maps.ControlPosition.TOP_LEFT
    },
    zoomControl: true,
    zoomControlOptions: {
        position: google.maps.ControlPosition.TOP_LEFT
    },
    mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),mapOptions);
var styles = [{
    url: '../icon_marker_cluster30.png',
    height: 30,
    width: 30,
    anchor: [5, 0],
    textColor: '#ffffff',
    textSize: 13
  }, {
    url: '../icon_marker_cluster40.png',
    height: 40,
    width: 40,
    anchor: [9, 0],
    textColor: '#ffffff',
    textSize: 14
  }, {
    url: '../icon_marker_cluster50.png',
    width: 50,
    height: 50,
    anchor: [13, 0],
    textColor: '#ffffff',
    textSize: 16
  }];

function init(){            
    latlng = new google.maps.LatLng(50.343597, 19.007915);
    marker['1'] = new google.maps.Marker({
            position: latlng,
            map: map
    });

    markers.push(marker['1']);

    marker['1'].addListener('click', function() {
        map.setZoom(15);
        map.setCenter(marker['1'].getPosition());
    });

    bounds.extend(latlng);

    markerInfo['1'] = createMarkerInfo("store", "address", "zipcode", "city");
    google.maps.event.addListener(marker['1'], 'click', function() {
        infoWindow.setContent(markerInfo['1']);
        infoWindow.open(map, marker['1']);
    });


    var markerCluster = new MarkerClusterer(map, markers, {styles: styles});

    google.maps.event.addListener(map, 'idle', function() {
        showVisibleMarkers();
    });

    map.fitBounds(bounds);
}

function createMarkerInfo(name, address, zip, city, phone = null, mail = null){
    var output = '';

    output += '<span class="label">' + name + '</span><br /><br />';
    output += address + '<br />';
    output += zip + ' ' +  city + '<br />';

    if(phone)
        output += '<br /><i class="fa fa-phone"></i> ' + phone;
    if(mail)
        output += '<br /><i class="fa fa-envelope"></i> <a href="mailto:' + mail + '">' + mail + '</a>';

    return output;
}

function showMarker(id){
    google.maps.event.trigger(marker[id], 'click');
    $('html, body').animate({
        scrollTop: $("#map").offset().top
    }, 500);
}

function showVisibleMarkers() {
    var bounds = map.getBounds();

    for (var i = 0; i < markers.length; i++) {
        var marker = markers[i],
            infoPanel = $('table tr[data-marker="'+i+'"]'); // array indexes start at zero, but not our class names :)

        if(bounds.contains(marker.getPosition())===true) {
            infoPanel.removeClass('hidden');
        }
        else {
            infoPanel.addClass('hidden');
        }
    }

    $("table tr").removeClass("odd");
    $("table tr:visible:odd").addClass("odd");
}

google.maps.event.addDomListener(window, "load", init);

我做了一些googleling并找到了一些“匿名函数”的提示,但我不知道问题发生的方式和位置。

修改 我可以将问题跟踪到函数'createMarkerInfo'。但仍然没有线索:(

1 个答案:

答案 0 :(得分:1)

我发现了错误:问题是createMarkerInfo函数的参数。如果您删除 phone = null,mail = null 一切正常