gpt4 book ai didi

google-maps - 无法在谷歌地图中使用 setMap(null) 或 setVisible(false) 清除标记

转载 作者:行者123 更新时间:2023-12-04 04:34:34 27 4
gpt4 key购买 nike

我在谷歌地图上使用了淘汰赛 javascrit,但我无法清除 map 上的标记,我在那里收到错误消息,错误如下

> Ripple :: Environment Warming Up (Tea. Earl Gray. Hot.) ripple.js:37
> web :: Initialization Finished (Make it so.) ripple.js:37 Uncaught
> TypeError: Object [object Object] has no method 'dxmap' Shops.js:70
> eula response: true ripple.js:47 Uncaught TypeError: Object [object
> Object] has no method 'dxmap' Shops.js:70 Uncaught TypeError: Object
> #<Object> has no method 'setMap' Shops.js:137

我下面的代码你能帮帮我吗
function FetchNearestShops(latitud,longitud)
{
$.ajax({
type: 'POST',
async:false,
contentType: 'application/json',
dataType: 'jsonp',
url: url + "/GetNearestShop",
//data: { Latitude: 9.998472, Longitude: 76.308059 },
data: { Latitude: latitud, Longitude: longitud },
success: function (data) {
loc.removeAll();
productsNear.removeAll();
$.map(data, function (item) {
loc.push({ label: item.ShopName, location: [item.Latitude, item.Longitude] });
//productsNear.push({ Name: item.ShopName, IsFavorite: false, Address: "", id: item.ShopId, Image: "mockcontent/shopimages/1.jpg" });
productsNear.push({ Name: item.ShopName, IsFavorite: item.Isfavourite, Address: item.Address, id: item.ShopId, Image: item.ImageUrl });
});
alert();
viewModel.options.markers = loc;

},
error: function () {
alert("error");
}

});
}
function SetLocation() {
var geocoder = new google.maps.Geocoder();
//var address = "ernakulam";
//alert(viewModel.options.location());
geocoder.geocode({ 'address': txtAddress() }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
ClearMap();

FetchNearestShops(latitude, longitude);
}
});
}
function ClearMap()
{
var markers = viewModel.options.markers();
for (var i = 0; i < markers.length; i++) {
markers[i];
markers.setMap(null);
}
markers;


}

最佳答案

我认为您的 ClearMap() 的循环有问题功能。尝试

for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}

而是 markers.setMap(null); .
我也不确定你的 markers它是谷歌标记的正确集合。
此集合应如下所示:
markers[i] = new google.maps.Marker({
position: new google.maps.LatLng('some latitude', 'some longitude'),
map: map, //object of Google Map
name: 'Marker Name'
});

关于google-maps - 无法在谷歌地图中使用 setMap(null) 或 setVisible(false) 清除标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19971157/

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