Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Accessing arguments in UI events</title>
- <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
- <meta charset="utf-8">
- <style>
- html, body, #map-canvas {
- height: 100%;
- margin: 0px;
- padding: 0px
- }
- </style>
- <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
- <script>
- var id;
- var markers = {};
- //var markers_arr = [];
- //var lat_lon_arr = [];
- function placeMarker(position, map) {
- var marker = new google.maps.Marker({
- position: position,
- map: map,
- draggable: true,
- animation: google.maps.Animation.DROP
- });
- //markers_arr.push(marker);
- //lat_lon_arr.push([position.lat(),position.lng()]);
- //LISTEN FOR RIGHT CLICK AND THEN DELETE ON MARKER
- id = marker.__gm_id;
- markers[id] = marker;
- google.maps.event.addListener(marker,
- "rightclick",
- function (point) {id = this.__gm_id; delMarker(id)
- });
- // lon_arr.push(position.lng());
- //map.panTo(position);
- }
- var delMarker = function(id){
- marker = markers[id];
- marker.setMap(null);
- }
- function initialize() {
- var mapOptions = {
- zoom: 5,
- center: new google.maps.LatLng(39.8250, -98.5555), //Center map at mid of USA
- mapTypeId: google.maps.MapTypeId.HYBRID
- };
- var map = new google.maps.Map(document.getElementById('map-canvas'),
- mapOptions);
- // WAITS AND LISTENS FOR USER'S ACTION TO CLICK GOOGLE MAP
- google.maps.event.addListener(map, 'click', function(e) {
- placeMarker(e.latLng, map);
- // alert('Lat: ' + e.latLng.lat() + ' Lng: ' + e.latLng.lng());
- });
- }
- google.maps.event.addDomListener(window, 'load', initialize);
- </script>
- </head>
- <body>
- <div id="map-canvas"></div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement