谷歌地图错误未捕获的语法错误:意外的令牌)

时间:2012-03-27 04:08:11

标签: jquery google-maps

我正在使用好友按,并在个人资料中添加了谷歌地图。有时地图会正确显示,有时则不会。

我检查了地图未显示的页面上的“检查元素”并获得“未捕获的语法错误:意外的令牌”任何人都可以帮我解决丢失的地图问题吗?

这是php代码供参考:

<script type="text/javascript">
jQuery.noConflict();

jQuery(document).ready(function() { 
if (jQuery('#member-map').length != 0) {

    function a_page_maps() {

        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(26.745610382199022, 2.63671875);
        var myOptions = {
            zoom: 2,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("member-map"), myOptions);

        var gmarkers = [];

        function createMarker(latlng,html,url,icon) {

            var contentString = html;
            var marker = new google.maps.Marker({
                position: latlng,
                map: map,
                icon: icon
            });

            gmarkers.push(marker);

            var infowindow = new google.maps.InfoWindow;

            google.maps.event.addListener(marker, 'mouseover', function() {
                infowindow.setContent(contentString); 
                infowindow.open(map,marker);
            });

            google.maps.event.addListener(marker, 'mouseout', function() {
                infowindow.close(map,marker);
            });

            google.maps.event.addListener(marker, 'click', function() {
                window.location = url;
            });

        }
        <?php
        foreach ($placel as $place) {
        if(get_post_meta($place, 'article_location', true) <> "") {
        ?>
var image = '<?php echo get_bloginfo('template_url'); ?>/images/red-pushpin.png';
                var point = new google.maps.LatLng(<?php echo get_post_meta($place, 'article_location_latlon', true); ?>);
            var html = "<h5><?php echo get_post_meta($place, 'article_location', true); ?></h5><p class='popup'><em>&darr; Click to see articles about this location &darr;</em></p>";
            var url = '<?php echo get_bloginfo('wpurl'); ?>/locations/?location=<?php echo urlencode(get_post_meta($place, 'article_location', true)); ?>';

            var marker = createMarker(point,html,url,image);

        <?php
        }
        }
        ?>

        <?php
        foreach ($placegol as $placego) {
        if(get_post_meta($placego, 'article_location', true) <> "") {
        ?>

            var image = '<?php echo get_bloginfo('template_url'); ?>/images/grn-pushpin.png';
            var point = new google.maps.LatLng(<?php echo get_post_meta($placego, 'article_location_latlon', true); ?>);
            var html = "<h5><?php echo get_post_meta($placego, 'article_location', true); ?></h5><p class='popup'><em>&darr; Click to see articles about this location &darr;</em></p>";
            var url = '<?php echo get_bloginfo('wpurl'); ?>/locations/?location=<?php echo urlencode(get_post_meta($placego, 'article_location', true)); ?>';

            var marker = createMarker(point,html,url,image);
        <?php
        }
        }
        ?>
    }
        a_page_maps();   
    }    
});
</script>

1 个答案:

答案 0 :(得分:0)

 var infowindow = new google.maps.InfoWindow;

应该是

 var infowindow = new google.maps.InfoWindow();

嵌套函数是个坏主意。而lnrbob说的是,发布实际生成的javascript,而不是PHP代码。