我正在使用来自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