谷歌地图与自定义图像

时间:2015-04-10 04:44:50

标签: javascript google-maps

你能帮我吗,请用自定义图像指针实现谷歌地图? 我在google devev site找到了这个代码示例 我已将其复制到页面,但地图不可见。你能告诉我为什么吗?



function initializeMap() {

  var newark = new google.maps.LatLng(40.740, -74.18);
  var imageBounds = new google.maps.LatLngBounds(
      new google.maps.LatLng(40.712216, -74.22655),
      new google.maps.LatLng(40.773941, -74.12544));

  var mapOptions = {
    zoom: 13,
    center: newark
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  historicalOverlay = new google.maps.GroundOverlay(
      'https://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',
      imageBounds);
  historicalOverlay.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initializeMap);

.row {
	height:300px;
	width:100%;
	border:1px solid red;
}

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&test=.js"></script>
<div class="container-fluid oH">
	<div class="row">
		<div class="col-xs-12 w100P" id="map-canvas">
			<div id="mapa"></div>
			<div id="map_bg"> </div>
		</div>	
	</div>
</div>
&#13;
&#13;
&#13;

jsfiddle

1 个答案:

答案 0 :(得分:1)

由于您尚未为map-canvas

设置css,因此无法看到地图
#map-canvas {
    height:300px;
    width:100%;
}

并且没有地图api也在这里看到我添加了这个 https://jsfiddle.net/L2x5kfeb/1/