gpt4 book ai didi

google-maps - Google Maps API v3 自定义标记未显示

转载 作者:行者123 更新时间:2023-12-02 00:35:25 25 4
gpt4 key购买 nike

我目前正在使用原始代码示例,但我什至无法让它工作!

我使用...调用创建标记

overlay = new CustomMarker(new google.maps.LatLng(subitem[2], subitem[3]), mapView);
overlay.setMap(mapView);

CustomMarker 的代码是

function CustomMarker(latlng,  map) {
google.maps.OverlayView.call(this);

this.latlng_ = latlng;

// Once the LatLng and text are set, add the overlay to the map. This will
// trigger a call to panes_changed which should in turn call draw.
this.set_map(map);


}


CustomMarker.prototype = new google.maps.OverlayView();

CustomMarker.prototype.draw = function() {
var me = this;

// Check if the div has been created.
var div = this.div_;
if (!div) {
// Create a overlay text DIV
div = this.div_ = document.createElement('DIV');
// Create the DIV representing our CustomMarker
div.style.border = "0px solid none";
div.style.position = "absolute";
div.style.paddingLeft = "0px";
div.style.cursor = 'pointer';

var img = document.createElement("img");
img.src = "../../images/tile_images/ship_black_0.png";
div.appendChild(img);
google.maps.event.addDomListener(div, "click", function(event) {
google.maps.event.trigger(me, "click");
});

// Then add the overlay to the DOM
var panes = this.get_panes();
panes.overlayImage.appendChild(div);
}

// Position the overlay
var point = this.get_projection().fromLatLngToDivPixel(this.latlng_);
if (point) {
div.style.left = point.x + 'px';
div.style.top = point.y + 'px';
}


};

CustomMarker.prototype.remove = function() {
// Check if the overlay was on the map and needs to be removed.
if (this.div_) {
this.div_.parentNode.removeChild(this.div_);
this.div_ = null;
}
};

CustomMarker.prototype.get_position = function() {
return this.latlng_;
};

使用相同的 LatLng 和 mapView 创建标准标记效果很好。

我得到的错误是

TypeError: Result of expression 'this.set_map' [undefined] is not a function.

最佳答案

看来

this.set_map(map); 

已弃用,现在是

this.setMap(map);

关于google-maps - Google Maps API v3 自定义标记未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4819688/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com