gpt4 book ai didi

javascript - 放置在 map 上后,除了谷歌地图中的前五个图标外,所有图标都消失了

转载 作者:行者123 更新时间:2023-11-30 06:42:02 25 4
gpt4 key购买 nike

我有一个带有谷歌地图的网页。我使用 javascript 根据来自 json 文件的地址在 map 上放置标记。 json文件中有7个地址。

加载 map 时,我在 map 上看到了所有 7 个图标,但它们立即消失,然后 map 随边界框调整大小。

我的代码是错误的还是我在 map 上可以拥有的图标数量有限制?无论查找多少个地址,它始终在 map 上保留 5 个图标。所有其他人都被删除。我怀疑是否存在限制,因为我见过带有数百个图标的 map 。

我确实为每个地址使用不同的图标。所以我删除了自定义图标并使用了谷歌提供的标准图标。同样的问题。所以,它似乎在代码中。帮助任何人。

// JavaScript Document
$(document).ready(function() {

var addresses = [];
var address, company;
var geocoder, marker, thumbtack;

var bounds = new google.maps.LatLngBounds();

// Set map options
var options = {
zoom:11,
center: new google.maps.LatLng(Lat, Lng),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
}
};

// Create the map
var map = new google.maps.Map(document.getElementById('map'), options);
marker = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(Lat, Lng),
title: "Your Zip Code"
});
//bounds.extend(new google.maps.LatLng(Lat, Lng));

// Get the data
// var listing is already set in footer.php
processFile(listings);

function processFile(listings) {
$.each(listings,function(business, info) {
address = info[2];
company = info[0];
thumbtack = info[4];
getCoordinates(address, company, thumbtack);
});
}


function getCoordinates(address, company, thumbtack) {
var counter = 0;
// Check to see if we already have a geocoded object. If not we create one.
if(!geocoder) {
geocoder = new google.maps.Geocoder();
}

// Create a GeocoderRequest object
var geocoderRequest = {
address: address
}

// Making the geocode request and adding marker
geocoder.geocode(geocoderRequest, function(results, status) {
// Check if status is OK before proceding
if (status == google.maps.GeocoderStatus.OK) {
addresses.push(results[0].geometry.location);
counter++;
marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: company,
//icon: "http://gmaps-samples.googlecode.com/svn/trunk/markers/blue/marker" + thumbtack + ".png"
icon: thumbtack
});
//bounds.extend(results[0].geometry.location);

// Adjusting the map to new bounding box
//map.fitBounds(bounds);

}

});

};

});

最佳答案

在我看来,您应该一次只看到一个标记。我建议添加一个 createMarker 函数,它可以使用函数闭包来创建 7 个标记。

Example使用 createMarker 函数。

关于javascript - 放置在 map 上后,除了谷歌地图中的前五个图标外,所有图标都消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10423905/

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