我在我的网站上使用 Google Maps API 自定义标记,它在桌面浏览器中运行良好,但不会出现在移动浏览器中。我的控制台出现错误: TypeError: Cannot read property 'length' of undefined.我使用ajax获取数据。这是javascript:var myLatlng = new google.maps.LatLng(-0.7893, 113.9213);var mapOptions = { zoom: 4, center: myLatlng, scrollwheel: false, mapTypeControl: false, styles: []};var locations = response;var map = new google.maps.Map(document.getElementById("map"), mapOptions);var infowindow = new google.maps.InfoWindow();var marker, i;for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][1], locations[i][2]), map: map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(locations[i][0]); infowindow.open(map, marker); } })(marker, i));}任何帮助,将不胜感激。
添加回答
举报
0/150
提交
取消