dai*_*hen 9 html javascript jquery google-maps google-maps-api-3
我有一个关于gmaps v0.3的问题,当我addMarker时,如何让infoWindow自动打开.不是当你打开时.
<script type="text/javascript">
var map;
$(document).ready(function(){
map = new GMaps({
div: '#map',
lat: 39.908403,
lng: 116.397529,
zoom: 1,
});
var marker = new google.maps.Marker();
marker = {
lat: 39.908403,
lng: 116.397529,
title: 'Lima',
//map: map.map,
//animation: google.maps.Animation.BOUNCE,
//shape: {coords: [0,0,50,50], type: "rect"},
infoWindow: {
content: '<font color="red">hello world</font>'
}
}
map.addMarker(marker);
});
Run Code Online (Sandbox Code Playgroud)
我想在addMarker自动打开infoWindow时不点击,我该怎么办.请帮我.
Tom*_*sen 16
您可以使用以下.open
函数打开infoWindow :
// Create map
var map = new GMaps({
div: '#map',
lat: 39.908403,
lng: 116.397529,
zoom: 1,
});
// Create infoWindow
var infoWindow = new google.maps.InfoWindow({
content: 'Content goes here..'
});
// Create marker
var marker = new google.maps.Marker({
lat: lat,
lng: lng,
title: 'Lima',
map: map.map,
infoWindow: infoWindow
});
// This opens the infoWindow
infoWindow.open(map, marker);
Run Code Online (Sandbox Code Playgroud)
您可以在Google地图网站上阅读infoWindow https://developers.google.com/maps/documentation/javascript/overlays#InfoWindows
添加到Gmaps.map intance的每个标记都有自己的InfoWindow存储在markers对象中.我们需要该特定标记的Array索引键.通过索引键的地址可以打开正确的InfoWinow.您可以通过执行以下操作打开GMaps.js特定标记:
(map.markers[index].infoWindow).open(map.map,map.markers[index]);
Run Code Online (Sandbox Code Playgroud)
将[index]替换为您希望InfoWindow打开的标记的索引.
归档时间: |
|
查看次数: |
18941 次 |
最近记录: |