Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Google Cluster Maps上标记标记_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在Google Cluster Maps上标记标记

Javascript 在Google Cluster Maps上标记标记,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,在另一个人的帮助下,我已经有了一张地图,可以把标记变成可点击的链接 我还需要标记具有某种类型的标签,以便用户知道它们将链接到哪里(现在,它们只是空白PIN),但我不确定如何修改此代码以在中构建该函数 function initMap() { var map = new google.maps.Map(document.getElementById('map'), { zoom: 7, center: {lat: 53.618939, lng: -2.1602328}

在另一个人的帮助下,我已经有了一张地图,可以把标记变成可点击的链接

我还需要标记具有某种类型的标签,以便用户知道它们将链接到哪里(现在,它们只是空白PIN),但我不确定如何修改此代码以在中构建该函数

function initMap() {

var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 7,
      center: {lat: 53.618939, lng: -2.1602328}
    });

var locations = [
 ["http://www.google.com", {lat: 53.618939, lng: -2.1601132}],
 ["http://www.google.com", {lat: 53.61953, lng: -2.1623746}],
 ["http://www.google.com", {lat: 53.6178993, lng: -2.1601596}],
 ["http://www.google.com", {lat: 53.5369545, lng: -1.9941523}],
 ["http://www.google.com", {lat: 53.5380496, lng: -1.9974085}],];

var markers = locations.map(function(location) {
    var marker = new google.maps.Marker({
        map: map,
        position: location[1],
        url: location[0] //Will be different for each marker
    });

    google.maps.event.addListener(marker, 'click', function(){
        window.location.href = this.url;
    });
    return marker;
});

// Add a marker clusterer to manage the markers.
var markerCluster = new MarkerClusterer(map, markers, {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}

要使用唯一的字母标记每个标记(至少26个标记),可以按照

代码片段:

//在下面的示例中,当用户单击地图时,会出现标记。
//每个标记都标有一个字母字符。
var标签='abcdefghijklmnopqrstuvxyz';
var labelIndex=0;
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:7,
中心:{
拉脱维亚:53.618939,
液化天然气:-2.1602328
}
});
变量位置=[
["http://www.google.com“,{lat:53.618939,lng:-2.1601132}],
["http://www.google.com“,{lat:53.61953,lng:-2.1623746}],
["http://www.google.com“,{lat:53.6178993,lng:-2.1601596}],
["http://www.google.com“,{lat:53.5369545,lng:-1.9941523}],
["http://www.google.com“,{lat:53.5380496,lng:-1.9974085}],
];
var markers=locations.map(函数(位置){
var marker=new google.maps.marker({
地图:地图,
位置:位置[1],
标签:标签[labelIndex++%labels.length],
url:位置[0]//对于每个标记都将不同
});
google.maps.event.addListener(标记'click',函数(){
window.location.href=this.url;
});
返回标记;
});
//添加标记群集器以管理标记。
var markerCluster=新的MarkerClusterer(地图、标记、{
imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'
});
}
google.maps.event.addDomListener(窗口“加载”,initMap)
html,
身体,
#地图{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}


您的意思是希望每个标记都用字母或数字进行唯一标记?例如?谢谢Geocodezip,我在文档中看到了标记的示例,但希望使用比a、B、C等更具描述性的标记。或者,由于所有标记都是已知的位置或企业,谷歌已经拥有的该位置的数据能否像谷歌地图中通常显示的那样显示出来。对不起,这只是改变了原来的问题!你想要什么标签?它应该来自输入数据吗?哪个领域?(没有一个明显的…)是data=string,我认为可以以某种方式引用它。也许我在抓救命稻草。。。我希望有某种方法可以在URL和long/lat信息旁边添加代码描述,这些信息将显示标记链接到的位置(例如“谷歌主页”)。在页面上的“标记标签”将是完美的,但链接是死的,所以我看不到任何关于它应该如何工作的信息。有可能在集群映射上实现类似的东西吗?什么是“data=string”?在你的问题中我看不到这一点。如果在
位置
数组中包含所需的标签,您当然可以在代码中使用它。当您在谷歌地图中单击位置时,URL的一部分(例如@53.6243957,-2.1747501,14z/data=!4m5!3m4!1s0x487bbeab0d589797:0xc53d55739819d57c!8m2!3d53.6361623!4d-2.1837795)。很可能不是这样,抱歉!我将在我的位置数组中添加一个标签,并查看是否可以从Google文档中获取更多信息,以便在“带有标签的标记”示例中显示标签。谢谢你的帮助。
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var labelIndex = 0;

var markers = locations.map(function(location) {
  var marker = new google.maps.Marker({
    map: map,
    position: location[1],
    label: labels[labelIndex++ % labels.length], 
    url: location[0] //Will be different for each marker
  });

  google.maps.event.addListener(marker, 'click', function() {
    window.location.href = this.url;
  });
  return marker;
});