【发布时间】:2015-08-04 02:27:10
【问题描述】:
我在谷歌地图页面上添加了导航栏,该页面从外部 json 文件中获取数据,但它没有正确显示地图。此外,它说空字符串在 jquery 移动文件中的 getelementbyID 中传递。有没有办法修复这个?
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas {height: 100%;margin:5% }
</style>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=something&sensor=false"></script>
<script type="text/javascript">
function initialize() {
var myOptions = {
center: new google.maps.LatLng(43.66207, -79.37617),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
$.getJSON('bikeshare.json', function(data) {
$.each( data.stationBeanList, function(i, value) {
var locationLatLong = new google.maps.LatLng(value.latitude, value.longitude);
var marker = new google.maps.Marker({
position: locationLatLong,
map: map,
icon:"img/bike.png",
title:"Bikes available: "+JSON.stringify(value.availableBikes)
});
var infoWindow = new google.maps.InfoWindow({
content:"Docks Available: "+JSON.stringify(value.availableDocks)
});
google.maps.event.addListener(marker, "click", function() {
infoWindow.open(map, marker);
});
});
});
}
</script>
</head>
<body onload="initialize()">
<div data-role="header" >
<h3>BIKESHARE</h3>
<div data-role="navbar" data-position="fixed">
<ul>
<li><a href="index.html" class="ui-btn-active ui-state-persist">Home</a> </li>
<li><a>Reports</a></li>
<li><a href="locations.html">Locations</a></li>
<li><a href="map.html">Map</a></li>
</ul>
</div>
</div>
<div data-role="content" id="map_canvas" ></div>
</body>
</html>
【问题讨论】:
-
请提供一个Minimal, Complete, Tested and Readable example 来证明该问题。我们需要您的 JSON(至少一个演示问题的示例)。
标签: javascript jquery html css google-maps-api-3