Set Map不是地图的实例,也不是街景Panaroma的实例



我在GoogleMaps API上运行Google文档中的代码时收到此错误:https://developers.google.com/maps/documentation/javascript/customoverlays

我正在尝试遵循所写的内容,这是我的代码:

var overlay;
CustomImageOverly.prototype = new google.maps.OverlayView();

function init() {
var pos= {lat: 62.323907, lng: -150.109291};
var mapProp= {
center:new google.maps.LatLng(pos),
zoom:4,
mapTypeId: google.maps.MapTypeId.TERRAIN,
styles: [{
featureType: 'water',
elementType: 'geometry',
stylers: [{color: '#3498DB'},
{visibility: 'on'}]
}]
};
var map = new google.maps.Map(document.getElementById("googleMap"),mapProp);

var bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(62.281819, -150.287132),
new google.maps.LatLng(62.400471, -150.005608));

var srcImage = 'https://developers.google.com/maps/documentation/' +
'javascript/examples/full/images/talkeetna.png';
debugger;
overlay = new CustomImageOverly(bounds, srcImage, map);
}
function CustomImageOverly(bounds, image, map)  {
this.bounds_ = bounds;
this.image_ = image;
this.map_ = map;
this.div_ = null;
this.setMap(map);
}

我做错了什么?

我想我做错了什么。我正在使用谷歌 api 方法,而没有先在我的 html 中初始化谷歌 api。

我从这里得到了答案:https://stackoverflow.com/a/58161132/3277177

<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY"></script>
<script src = "map.js"></script>

然后在我的Javascript代码中:

var map;
CustomImageOverly.prototype = new google.maps.OverlayView();
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: -34.397,
lng: 150.644
},
zoom: 8
});
var bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(62.281819, -150.287132),
new google.maps.LatLng(62.400471, -150.005608));
// The photograph is courtesy of the U.S. Geological Survey.
var srcImage = 'https://developers.google.com/maps/documentation/javascript/';
srcImage += 'examples/full/images/talkeetna.png';
overlay = new CustomImageOverly(bounds, srcImage, map);
}
function CustomImageOverly(bounds, image, map) {
this.bounds_ = bounds;
this.image_ = image;
this.map_ = map;
this.div_ = null;
this.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initMap);

最新更新