zoukankan      html  css  js  c++  java
  • google map 删除标记

    <!DOCTYPE html>
    
    <html> 
    
    <head> 
    
    <title>Google Maps JavaScript API v3 Example: Overlay Removal</title>
    
    <link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
    
    <script type="text/javascript"> 
    
      var map;
    
      var markersArray = [];
    
    
    
      function initialize() {
    
        var haightAshbury = new google.maps.LatLng(37.7699298, -122.4469157);
    
        var mapOptions = {
    
          zoom: 12,
    
          center: haightAshbury,
    
          mapTypeId: google.maps.MapTypeId.TERRAIN
    
        };
    
        map = new google.maps.Map(document.getElementById("map_canvas"),
    
            mapOptions);
    
    
    
        google.maps.event.addListener(map, 'click', function(event) {
    
          addMarker(event.latLng);
    
        });
    
      }
    
      
    
      function addMarker(location) {
    
        marker = new google.maps.Marker({
    
          position: location,
    
          map: map
    
        });
    
        markersArray.push(marker);
    
      }
    
    
    
     // Removes the overlays from the map, but keeps them in the array
    
      function clearOverlays() {
    
        if (markersArray) {
    
          for (i in markersArray) {
    
            markersArray[i].setMap(null);
    
          }
    
        }
    
      }
    
    
    
      // Shows any overlays currently in the array
    
      function showOverlays() {
    
        if (markersArray) {
    
          for (i in markersArray) {
    
            markersArray[i].setMap(map);
    
          }
    
        }
    
      }
    
    
    
      // Deletes all markers in the array by removing references to them
    
      function deleteOverlays() {
    
        if (markersArray) {
    
          for (i in markersArray) {
    
            markersArray[i].setMap(null);
    
          }
    
          markersArray.length = 0;
    
        }
    
      }
    
    </script> 
    
    </head> 
    
    <body onload="initialize();"> 
    
      <div>
    
        <input onclick="clearOverlays();" type=button value="Clear Overlays"/>
    
        <input onclick="showOverlays();" type=button value="Show All Overlays"/>
    
        <input onclick="deleteOverlays();" type=button value="Delete Overlays"/> 
    
      </div> 
    
      <div id="map_canvas" style="600px; height:500px"></div> 
    
    </body> 
    
    </html> 
    
  • 相关阅读:
    设计模式C++描述----15.策略(Strategy)模式
    设计模式C++描述----14.外观(Facade)模式
    设计模式C++描述----12.享元(Flyweight)模式
    设计模式C++描述----13.代理(Proxy)模式
    设计模式C++描述----11.组合(Composite)模式
    设计模式C++描述----10.装饰(Decorator)模式
    爬虫之urllib包以及request模块和parse模块
    爬虫简介
    爬虫知识总汇
    Django之admin的使用和源码剖析
  • 原文地址:https://www.cnblogs.com/xiangniu/p/2062322.html
Copyright © 2011-2022 走看看