0
我使用PHP從MySQL數據創建JSON文件。 當我點擊標記時,我想要做的是在谷歌地圖上的信息窗口中顯示一些這些數據。谷歌地圖V3 InfoWindow從JSON不顯示
目前,我可以得到所有的標記出現,但我收到錯誤:
Uncaught ReferenceError: InfoWnd is not defined
我認爲我在做我中設置的信息窗口的方式有些錯誤,但我已經嘗試了一把方式和我總是收到相同的錯誤信息。
這是我的JavaScript至今:
**要初始化地圖畫布:
<script type="text/javascript">
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(48.476, -81.312),
zoom: 18,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
}
</script>
<body onload="initialize()">
<div id="map_canvas" style="width=80%; height: 100%"></div>
**和創建標記/信息窗口:
<script type="text/javascript">
var blueIcon = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
var redIcon = "http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png";
var greenIcon = "http://www.google.com/intl/en_us/mapfiles/ms/micons/green-dot.png";
infoWnd = new google.maps.InfoWindow();
$(document).ready(function() {
$.ajax({
url: 'http://localhost/testing/map_json.php',
dataType: 'json',
success: function (jsonData) {
$.each(jsonData, function(key, data) {
var latLng = new google.maps.LatLng(data.lat, data.lng);
// creating marker, putting it on map
// If no sensor reading data is present, RTU is assumed to be repeater node.
// Displayed in blue and Info Window only displays system voltage and time of reading.
if (data.R_1 === undefined) {
if (data.SysV >= 6.5) {
var marker = new google.maps.Marker({
position: latLng,
title: data.RTU_Addr,
icon: blueIcon
});
setInfoWindow();
}
else {
var marker = new google.maps.Marker({
position: latLng,
title: data.RTU_Addr,
icon: redIcon
});
setInfoWindow();
}
}
// If sensor data is present, RTU is assumed to be end unit.
// Displayed in red/green and Info Window displays all readings along with timestamp and voltage.
else {
if (data.SysV >= 6.5) {
var marker = new google.maps.Marker({
position: latLng,
title: data.RTU_Addr,
icon: greenIcon
});
setInfoWindow();
}
else {
var marker = new google.maps.Marker({
position: latLng,
title: data.RTU_Addr,
icon: redIcon
});
setInfoWindow();
}
}
marker.setMap(map);
function setInfoWindow() {
google.maps.event.addListener(marker, 'click', function() {
infoWnd.setContent("hi");
InfoWnd.open(map, marker);
});
};
});
}
});
});
</script>
任何想法我哪裏錯了?
哇。我猜你盯着某個東西夠久了,而你卻錯過了那些東西。謝謝! – lrich