0
我使用好友新聞並在配置文件中添加了谷歌地圖。有時地圖顯示正確,有時不顯示。谷歌地圖錯誤未捕獲的語法錯誤:意外的代幣)
我檢查「檢查元素」的頁面,地圖顯示不出來,並得到了「未捕獲的語法錯誤上:意外令牌)誰能幫我解決了缺少地圖問題
這裏的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>↓ Click to see articles about this location ↓</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>↓ Click to see articles about this location ↓</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>
您收到的錯誤消息意味着您在代碼中缺少單個')'。使用Firebug(用於FF)或內置的Dev Tools(Chrome和Safari)等調試工具,他們會將您指向缺少字符的確切線路!通常,您會在每個語法錯誤旁邊都有一個行號,您可以點擊它,並在不及時的情況下查看並修復錯誤。見[這個例子](http://getfirebug.com/javascript) – m90 2012-03-27 07:15:14
它可能是有道理的,因爲結果JavaScript代碼添加到問題 - 這應該是更容易發現一個JavaScript錯誤比PHP。 – lnrbob 2012-03-27 09:03:59