网站嵌入自定义 google 地图

Q:想在页面上嵌入一个谷歌地图框架。 而且可以在同一框架中自定义多个标记。如下:

在这里插入图片描述

A: 这里有一个示例,说明如何向地图添加三个标记:

<!DOCTYPE html>
<html>
  <head>
    <title>Multiple Markers Example</title>
    <style>
      #map {
     
        height: 400px;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <h1>Multiple Markers Example</h1>
    <div id="map"></div>
    <script>
      function initMap() {
     
        var locations = [
          ['Location 1', 40.7128, -74.0060],
          ['Location 2', 34.0522, -118.2437],
          ['Location 3', 51.5074, -0.1278]
        ];
        var map = new google.maps.Map(document.getElementById('map'), {
     
          zoom: 4,
          center: new google.maps.LatLng(40.7128, -74.0060),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });
        var infowindow = new google.maps.InfoWindow();
        var marker, i;
        for (i = 0; i < locations.length; i++) {
     
          marker = new google.maps.Marker({
     
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map
          });
          google.maps.event.addListener(marker, 'click', (function(marker, i) {
     
            return function() {
     
              infowindow.setContent(locations[i][0]);
              infowindow.open(map, marker);
            }
          })(marker, i));
        }
      }
    </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap"><
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值