0
我堅持在我的網站上實施豐富網頁摘要。 頁面遵守schema.org/MusicEvent標準。但我無法弄清楚如何提取ncenter中包含的座標對以填充html代碼中的經度和緯度元標籤。從谷歌地圖API到豐富的片段geocoords
var geocoder = new google.maps.Geocoder();
var map;
var ncenter;
function initialize() {
var address = document.getElementById("address").firstChild.data;
geocoder.geocode({'address':address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
ncenter = results[0].geometry.location;
var mapOptions = {
zoom:12,
center:ncenter,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map=new google.maps.Map(document.getElementById("map"),mapOptions);
var marker = new google.maps.Marker({
map:map,
position:ncenter
});
} else {
alert("Geocode ERROR: " + status);
}
});
}
window.onload=initialize;
此外,這不會與搜索引擎的蜘蛛,因爲他們不運行JS。 有沒有其他解決方案(基於PHP的查詢也許)?
感謝您的回答,我終於選擇實施基於PHP的解決方案,這要歸功於XML地理編碼器。 我解析XML以查找經度和緯度,並用簡單的回聲填充元標記。然後,JS只需獲取元標記的內容值來構建座標對,並在該點創建一個具有中心和標記的地圖。 – Vektor88