Google maps-api v3 InfoWindow 在页面加载时自动打开 [英] Google maps-api v3 InfoWindow automatically open on page load

查看:28
本文介绍了Google maps-api v3 InfoWindow 在页面加载时自动打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用 Google Maps api-v3 的项目,在地图上会有一些位置标记,其中包含我存储在 InfoWindow 中的信息.

I am working on a project where I am using the Google Maps api-v3 , On the map there will be a few place markers containing information that I am storing in an InfoWindow.

我想知道是否可以将 InfoWindow 设置为在页面加载时自动打开(即在没有用户交互的情况下自动打开).

I am wondering is there anyway that you can set an InfoWindow to automatically open on the page load (i.e automatically open without user interaction).

在网上搜索我似乎发现它需要绑定到事件侦听器,但 InfoWindow 对象似乎具有的所有事件都是鼠标事件.

Searching online all I can seem to find is that it needs to be tied to an event listener but all the events the InfoWindow object seems to have are mouse events.

有人知道各种解决方法吗?

Does anyone know of a workaround of sorts ?

推荐答案

不确定我是否完全理解你的问题,但这对我使用硬编码的 LatLng 有用:

Not sure I fully understand your question but this works for me with a hard-coded LatLng:

var infoWindow = null;
function initialize() 
{
    infoWindow = new google.maps.InfoWindow();
    var windowLatLng = new google.maps.LatLng(43.25,-68.03);
    infoWindow.setOptions({
        content: "<div>This is the html content.</div>",
        position: windowLatLng,
    });
    infoWindow.open(map); 
} // end initialize

google.setOnLoadCallback(initialize);

这篇关于Google maps-api v3 InfoWindow 在页面加载时自动打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆