【发布时间】:2015-09-29 11:07:15
【问题描述】:
twistSection(document.getElementById('page:form:resultsBlock:debugSection').childNodes[0].childNodes[0]); // initially hide the debug section
var contacts = {
!contactsJson
}; // Array of contact data, some of them might have lat/long info, some we'll have to geocode client side
var coords = []; // Just the latitude/longitude for each contact
var requestCounter = 0;
var markers = []; // Red things we pin to the map.
var balloon = new google.maps.InfoWindow(); // Comic-like baloon that floats over markers.
function geocodeClientSide() {
for (var i = 0; i < contacts.length; i++) {
if (contacts[i].Location__Latitude__s != null && contacts[i].Location__Longitude__s != null) {
coords.push(new google.maps.LatLng(contacts[i].Location__Latitude__s, contacts[i].Location__Longitude__s));
} else {
++requestCounter;
var address = contacts[i].MailingStreet + ' ' + contacts[i].MailingCity + ' ' + contacts[i].MailingCountry;
var geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
coords.push(results[0].geometry.location);
} else {
var pTag = document.createElement("p");
pTag.innerHTML = status;
document.getElementById('log').appendChild(pTag);
}
if (--requestCounter == 0) {
drawMap();
}
});
}
}
}
// It could be the case that all was geocoded on server side (or simply retrieved from database).
// So if we're lucky - just proceed to drawing the map.
if (requestCounter == 0) {
drawMap();
}
}
function drawMap() {
var mapOptions = {
center: coords[0],
zoom: 3,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
for (var i = 0; i < coords.length; ++i) {
var marker = new google.maps.Marker({
map: map,
position: coords[i],
title: contacts[i].Name,
zIndex: i
});
google.maps.event.addListener(marker, 'click', function () {
var index = this.zIndex;
balloon.content = '<b>' + contacts[index].Name + '</b><br/>' + contacts[index].Account.Name + '<br/>' + contacts[index].Email;
balloon.open(map, marker, content);
});
markers.push(marker);
}
}
geocodeClientSide();
我正在绘制来自 salesforce 的联系人地址列表。它在地图上正确绘制了气球,但没有显示任何内容。
我尝试了很多可能的方法,但我没有在气球上看到内容 谁能告诉我问题出在哪里?
提前致谢
【问题讨论】:
-
请编辑您的问题(而不是气球放 infowindow 这是气球的适当词)。把你的代码放在一个小提琴中。
-
@MrUpsidown balloon=infowindow,看看气球的功能……
-
我知道这是一个信息窗口...这只是让 OP 知道这不清楚的一种方式。
-
@MrUpsidown 我已经编辑了我的问题,让我知道你的疑问
-
@eugensunic 它已经在顶部启动了信息窗口
标签: javascript google-maps dictionary google-maps-api-3