JS如下:

(function() {

window.onload = function() {

// Creating an object literal containing the properties

// you want to pass to the map

var options = {

zoom: 3,

center: new google.maps.LatLng(37.09, -95.71),

mapTypeId: google.maps.MapTypeId.ROADMAP

};

// Creating the map

var map = new google.maps.Map(document.getElementById('map'), options);

// Creating an array which will contain the coordinates

// for New York, San Francisco and Seattle

var places = [];

// Adding a LatLng object for each city

places.push(new google.maps.LatLng(40.756, -73.986));

places.push(new google.maps.LatLng(37.775, -122.419));

places.push(new google.maps.LatLng(47.620, -122.347));

// Creating a variable that will hold the InfoWindow object

var infowindow;

// Looping through the places array

for (var i = 0; i < places.length; i++) {

// Adding the markers

var marker = new google.maps.Marker({

position: places[i],

map: map,

title: 'Place number ' + i

});

// Wrapping the event listener inside an anonymous function

// that we immediately invoke and passes the variable i to.

(function(i, marker) {

// Creating the event listener. It now has access to the values of

// i and marker as they were during its creation

google.maps.event.addListener(marker, 'click', function() {

if (!infowindow) {

infowindow = new google.maps.InfoWindow();

}

// Setting the content of the InfoWindow

infowindow.setContent('Place number ' + i);

// Tying the InfoWindow to the marker

infowindow.open(map, marker);

});

})(i, marker);

}

};

})();

CSS如下:

body {

font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;

font-size: small;

background: #fff;

}

#map {

width: 100%;

height: 500px;

border: 1px solid #000;

}

.info {

width: 250px;

}

HTML如下:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>My first map</title>

<link type="text/css" href="css/style.css" rel="stylesheet" media="all" />

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script type="text/javascript" src="js/map.js"></script>

</head>

<body>

<h1>My first map</h1>

<div id="map"></div>

</body>

</html>

效果如下:

转载于:https://www.cnblogs.com/my4piano/p/5327140.html

在Google Maps 上点击标签后显示说明相关推荐

  1. MyEclipse导入主题文件epf后xml及jsp等页面中点击标签之后显示灰白

    MyEclipse导入主题文件epf后xml及jsp等页面中点击标签之后显示灰白,症状如下: 解决方案如下:

  2. 解决在工具栏Chrome图标上点击右键会显示“常去网站”和“最后关闭网站”的问题

    解决在工具栏Chrome图标上点击右键会显示"常去网站"和"最后关闭网站"的问题 参考文章: (1)解决在工具栏Chrome图标上点击右键会显示"常去 ...

  3. 解决在工具栏Chrome图标上点击右键会显示“常去网站”和“最后关闭网站”的问题...

    在工具栏Chrome图标上点击右键,可以"打开新窗口"或"打开新的隐身窗口"很方便,但是在其他电脑上尝试该操作时,发现有些情况下还会显示"常去网站&q ...

  4. My97DatePicker日历的平面显示,不是文本框点击事件后显示

    二. 功能及示例 2. 特色功能 平面显示 日期控件支持平面显示功能,只要设置一下eCont属性就可以把它当作日历来使用了,无需触发条件,直接显示在页面上 示例2-1 平面显示演示 <div i ...

  5. swift 如何实现点击view后显示灰色背景

    有这样一种场景,当我们点击view的时候,需要过0.几秒显示一个灰色或者别的颜色的背景 用button来实现,只有按下去的时候才会出现,往往在快速按下,快速抬起的时候是看不出这个变化的 下边是解决方案 ...

  6. Google maps javascript api v3 叠加层(Overlays)介绍

    很多人尝试google maps api的开发,通常会涉及到在Google maps上进行标注功能的开发.Helloj2ee学习一项技术通常不在看书,而是多以帮助为主.当我看完之后,我将Overlay ...

  7. Google Maps JavaScript API V3 叠加层

    注意:以下网页中提到的 Google Maps JavaScript API 第 3 版现在是正式的 JavaScript API 版本.该 API 的第 2 版已根据我们的弃用政策正式弃用.欢迎您将 ...

  8. Google Maps JavaScript API V3的使用(四)

    Google Maps JavaScript API V3 叠加层 叠加层概述 叠加层是地图上与纬度/经度坐标绑定的对象,会随您拖动或缩放地图而移动.叠加层表示的是"添加"到地图中 ...

  9. 怎么在谷歌地图上画图_如何在Google地图上规划具有多个目的地的公路旅行

    怎么在谷歌地图上画图 Whether you're planning a day out on the town, or want to orchestrate the perfect road tr ...

最新文章

  1. 神奇的 SQL,Group By 真扎心,原来是这样!
  2. [转]Iphone NSString字符串常用方法
  3. 在 Linux 下运行 ASP.NET 2.0
  4. Boost.Signals2 的初学者你好世界示例
  5. Ztree手风琴效果(第三版)
  6. 洛谷——P1017 进制转换
  7. birt 报表设计(2)—介绍
  8. windows server 2008安装wampserver后几种小问题个人总结
  9. 基于PHP构建OAuth 2.0 认证平台
  10. python自动化测试流程_接口自动化基本流程(python)
  11. vue单元测试vue test utils使用初探
  12. 批量修改密码脚本--------小练习
  13. 增强学习训练AI玩游戏
  14. 史上最简单的LSTM文本分类实现:搜狗新闻文本分类(附代码)
  15. 王强 河南大学计算机学院,王强-河南大学生命科学学院
  16. mysql 学习指南
  17. 浏览量比较大的网站应该从哪几个方面入手
  18. Java中的专业术语
  19. 干扰:内部干扰/外部干扰/杂散干扰/互调干扰/阻塞干扰
  20. 轻松白嫖几十T硬盘空间,阿里云盘转本地硬盘小工具分享~

热门文章

  1. dup和dup2的使用方法
  2. 前端学习(3330):闭包的形式6
  3. react学习(67)--git 屏蔽文件不被追踪
  4. [html] img中的src加载失败时如何用默认图片来替换呢?
  5. PS教程第九课:背景色
  6. [vue] 说说你对vue的mixin的理解,有什么应用场景?
  7. [css] 如何做图片预览,如何放大一个图片?
  8. 前端学习(2667):退出编辑状态
  9. 前端学习(2330):angular之二级路由
  10. 前端学习(1968)vue之电商管理系统电商系统之将不同的参数挂载到数据源上