我正在使用來自Google的一段代碼,試圖改變它,使得替代windows.alerting LT/LN座標,座標得到保存在一個數組中然後可以顯示在某種表格中。將JavaScript添加到數組中並將其顯示在html中
function geocodeAddress(geocoder, resultsMap) {
var cords = []; //my array
var address = document.getElementById('address').value;
geocoder.geocode({'address': address}, function(results, status) {
if (status === 'OK') {
window.alert("Coordinates:" + results[0].geometry.location); //current alert
cords.push(results[0].geometry.location); //adding to an Array
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
我很生鏽的JS,所以我甚至不知道它是否存儲在數組中。我嘗試了很多種方法來顯示數組到屏幕上,但沒有任何工作,我不知道這是否因爲沒有存儲在數組中,或者因爲我沒有正確顯示數組。
明確提出:關於如何存儲陣列&這些座標我應該如何去顯示這個陣列在屏幕上任何想法?乾杯。
您可以用'的console.log(軟線)'和開放的開發工具(F12)查看輸出,但它看起來* *罰款。至於將它們添加到html,有一個可能的解決方案的傳說;這裏是一個香草JS實現:http://stackoverflow.com/questions/5886144/create-divs-from-array-elements – Pogrindis