Javascript 谷歌地图上的markercluster问题
当我试图用下面的代码在谷歌地图上显示标记集群时,它抛出了一些错误。请查找以下代码和错误。 当我在salesforce外部执行代码时,它正在工作,但在Vf页面内部,它不工作。有人能帮我吗Javascript 谷歌地图上的markercluster问题,javascript,salesforce,Javascript,Salesforce,当我试图用下面的代码在谷歌地图上显示标记集群时,它抛出了一些错误。请查找以下代码和错误。 当我在salesforce外部执行代码时,它正在工作,但在Vf页面内部,它不工作。有人能帮我吗 <apex:page standardController="Account"> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<apex:page standardController="Account">
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta charset="utf-8"/>
<title>Marker Clustering</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: {lat: -28.024, lng: 140.887}
});
// Create an array of alphabetical characters used to label the markers.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length]
});
});
// 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'});
}
var locations = [
{lat: -31.563910, lng: 147.154312},
{lat: -33.718234, lng: 150.363181},
{lat: -33.727111, lng: 150.371124},
{lat: -33.848588, lng: 151.209834},
{lat: -33.851702, lng: 151.216968},
{lat: -34.671264, lng: 150.863657},
{lat: -35.304724, lng: 148.662905},
{lat: -36.817685, lng: 175.699196},
{lat: -36.828611, lng: 175.790222},
{lat: -37.750000, lng: 145.116667},
{lat: -37.759859, lng: 145.128708},
{lat: -37.765015, lng: 145.133858},
{lat: -37.770104, lng: 145.143299},
{lat: -37.773700, lng: 145.145187},
{lat: -37.774785, lng: 145.137978},
{lat: -37.819616, lng: 144.968119},
{lat: -38.330766, lng: 144.695692},
{lat: -43.999792, lng: 170.463352}
]
</script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js">
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA8Bz5GIlx4K7sBv2ZLjr5HUtHhkTx2TMk&callback=initMap">
</script>
</body>
</html>
</apex:page>
标记聚类
/*始终明确设置贴图高度以定义div的大小
*包含映射的元素*/
#地图{
身高:100%;
}
/*可选:使示例页面填充窗口*/
html,正文{
身高:100%;
保证金:0;
填充:0;
}
函数initMap(){
var map=new google.maps.map(document.getElementById('map'){
缩放:3,
中心:{纬度:-28.024,液化天然气:140.887}
});
//创建用于标记的字母字符数组。
var标签='abcdefghijklmnopqrstuvxyz';
//在地图上添加一些标记。
//注意:代码使用JavaScript Array.prototype.map()方法
//基于给定的“位置”数组创建标记数组。
//这里的map()方法与Google Maps API无关。
var markers=locations.map(函数(位置,i){
返回新的google.maps.Marker({
位置:位置,,
标签:标签[i%标签.长度]
});
});
//添加标记群集器以管理标记。
var markerCluster=新的MarkerClusterer(地图、标记、,
{imagePath:'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});
}
变量位置=[
{拉丁美洲:-31.563910,液化天然气:147.154312},
{拉脱维亚:-33.718234,液化天然气:150.363181},
{拉丁美洲:-33.727111,液化天然气:150.371124},
{拉丁美洲:-33.848588,液化天然气:151.209834},
{拉丁美洲:-33.851702,液化天然气:151.216968},
{拉丁美洲:-34.671264,液化天然气:150.863657},
{拉丁美洲:-35.304724,液化天然气:148.662905},
{拉丁美洲:-36.817685,液化天然气:175.699196},
{拉丁美洲:-36.828611,液化天然气:175.790222},
{拉脱维亚:-37.750000,液化天然气:145.116667},
{拉丁美洲:-37.759859,液化天然气:145.128708},
{拉丁美洲:-37.765015,液化天然气:145.133858},
{拉丁美洲:-37.770104,液化天然气:145.143299},
{拉丁美洲:-37.773700,液化天然气:145.145187},
{拉丁美洲:-37.774785,液化天然气:145.137978},
{lat:-37.819616,lng:144.968119},
{拉丁美洲:-38.330766,液化天然气:144.695692},
{拉丁美洲:-43.999792,液化天然气:170.463352}
]
当我在salesforce外部执行代码时,它正在工作,但在Vf页面内部它不工作。有人能帮我吗?请在提问之前校对您的问题。我已编辑了问题,请忽略任何错误。StackoverflowStack Overflow是一个Q+a论坛,旨在展示其问题和答案,因此专业人士和狂热爱好者有充分的理由使用我们在这里提供的信息。不恰当的问题是不鼓励的。“我”应该大写,“请查找代码和错误”毫无意义。“有人能帮我吗?”中的“c”应该大写,并且在几个地方缺少逗号。请改正这些错误。意思是,上面的问题不清楚?我已经发布了我面临的问题和我尝试过的代码。请在提问之前校对您的问题。我已经编辑了问题,请忽略任何错误。StackoverflowStack Overflow是一个Q+a论坛,旨在展示其问题和答案,因此专业人士和狂热爱好者有充分的理由使用我们在这里提供的信息。不恰当的问题是不鼓励的。“我”应该大写,“请查找代码和错误”毫无意义。“有人能帮我吗?”中的“c”应该大写,并且在几个地方缺少逗号。请改正这些错误。意思是,上面的问题不清楚?我已经发布了我面临的问题和我尝试的代码。
<apex:page standardController="Account">
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta charset="utf-8"/>
<title>Marker Clustering</title>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: {lat: -28.024, lng: 140.887}
});
// Create an array of alphabetical characters used to label the markers.
var labels = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
// Add some markers to the map.
// Note: The code uses the JavaScript Array.prototype.map() method to
// create an array of markers based on a given "locations" array.
// The map() method here has nothing to do with the Google Maps API.
var markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location,
label: labels[i % labels.length]
});
});
// 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'});
}
var locations = [
{lat: -31.563910, lng: 147.154312},
{lat: -33.718234, lng: 150.363181},
{lat: -33.727111, lng: 150.371124},
{lat: -33.848588, lng: 151.209834},
{lat: -33.851702, lng: 151.216968},
{lat: -34.671264, lng: 150.863657},
{lat: -35.304724, lng: 148.662905},
{lat: -36.817685, lng: 175.699196},
{lat: -36.828611, lng: 175.790222},
{lat: -37.750000, lng: 145.116667},
{lat: -37.759859, lng: 145.128708},
{lat: -37.765015, lng: 145.133858},
{lat: -37.770104, lng: 145.143299},
{lat: -37.773700, lng: 145.145187},
{lat: -37.774785, lng: 145.137978},
{lat: -37.819616, lng: 144.968119},
{lat: -38.330766, lng: 144.695692},
{lat: -43.999792, lng: 170.463352}
]
</script>
<script src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js">
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA8Bz5GIlx4K7sBv2ZLjr5HUtHhkTx2TMk&callback=initMap">
</script>
</body>
</html>
</apex:page>