日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在Google Maps 上点击标签后显示说明

發布時間:2023/12/10 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在Google Maps 上点击标签后显示说明 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 上点击标签后显示说明的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。