<script
src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script>
var geocoder = new google.maps.Geocoder();
<%for (String st : t.keySet()) {%>
printGeocode( <%=t.get(st)[1]%> , <%=t.get(st)[0]%> );
<%}%>
function printGeocode(x, y) {
document.write("Test Check1<br>"); // work fine
alert("test Check1"); // work fine
var latlng = new google.maps.LatLng(x, y);
geocoder.geocode({
'latLng' : latlng
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
document.write(results[1].formatted_address+"<br>"); // didn't work
alert(results[1].formatted_address); // Work Fine
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
</script>
這是我的源的Javascript API GoogleMap的文件撰寫()不工作
警報(字符串)是做工精細
但文件撰寫就是不工作
什麼是第一 「document.write("Test Check1<br>"); // work fine
」
和document.write(results[1].formatted_address+"<br>");
出現警報的地址爲什麼
document.write(results[1].formatted_address+"<br>"); // didn't work
沒有出現在網頁上?
使用document.write不好。更好的操作DOM,像'document.getElementById('id')。innerHTML = results [1] .formatted_address +「
」' – Praveen