Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.98 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.   <head>
  4.     <title>Accessing arguments in UI events</title>
  5.     <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
  6.     <meta charset="utf-8">
  7.     <style>
  8.       html, body, #map-canvas {
  9.         height: 100%;
  10.         margin: 0px;
  11.         padding: 0px
  12.       }
  13.     </style>
  14.     <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
  15.     <script>
  16.       var id;
  17.       var markers = {};
  18.       //var markers_arr = [];
  19.       //var lat_lon_arr = [];
  20.       function placeMarker(position, map) {
  21.         var marker = new google.maps.Marker({
  22.           position: position,
  23.           map: map,
  24.           draggable: true,
  25.           animation: google.maps.Animation.DROP
  26.         });
  27.  
  28.         //markers_arr.push(marker);
  29.         //lat_lon_arr.push([position.lat(),position.lng()]);
  30.  
  31.         //LISTEN FOR RIGHT CLICK AND THEN DELETE ON MARKER
  32.         id = marker.__gm_id;
  33.         markers[id] = marker;
  34.         google.maps.event.addListener(marker,
  35.           "rightclick",
  36.           function (point) {id = this.__gm_id; delMarker(id)
  37.           });
  38.  
  39.  
  40.         // lon_arr.push(position.lng());
  41.         //map.panTo(position);
  42.       }
  43.  
  44.       var delMarker = function(id){
  45.         marker = markers[id];
  46.         marker.setMap(null);
  47.       }
  48.  
  49.       function initialize() {
  50.         var mapOptions = {
  51.           zoom: 5,
  52.           center: new google.maps.LatLng(39.8250, -98.5555), //Center map at mid of USA
  53.           mapTypeId: google.maps.MapTypeId.HYBRID
  54.         };
  55.         var map = new google.maps.Map(document.getElementById('map-canvas'),
  56.             mapOptions);
  57.  
  58.         // WAITS AND LISTENS FOR USER'S ACTION TO CLICK GOOGLE MAP
  59.         google.maps.event.addListener(map, 'click', function(e) {
  60.           placeMarker(e.latLng, map);
  61.           // alert('Lat: ' + e.latLng.lat() + ' Lng: ' + e.latLng.lng());
  62.         });
  63.       }
  64.  
  65.       google.maps.event.addDomListener(window, 'load', initialize);
  66.  
  67.     </script>
  68.   </head>
  69.   <body>
  70.     <div id="map-canvas"></div>
  71.   </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement