1
我想顯示標記點擊標題/描述。標記正在顯示,但點擊描述不會顯示。我在控制檯日誌中看到錯誤消息是「Uncaught TypeError:無法讀取屬性'0'未定義的行40號」,我不知道我的代碼有什麼問題,任何人都可以幫助我嗎?谷歌地圖不顯示標記描述
var locations = [
['Asia','Asia'],
['America','America'],
['India','India']
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 1,
center: new google.maps.LatLng(0,0),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
\t var url = 'http://maps.googleapis.com/maps/api/geocode/json?address='+locations[i][1]+'&sensor=false';
$.getJSON(url, function (data) {
var p = data.results[0].geometry.location;
var latlng = new google.maps.LatLng(p.lat, p.lng);
marker = new google.maps.Marker({
position: latlng,
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
});
}
#map{
height:400px;
width:500px;
}
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.1.min.js"></script>
<div id="map"></div>
<