Created
January 30, 2017 20:05
-
-
Save Kcko/5b583d983f8f0cd0480017df12b7b86d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
| <title>Multiple Markers Google Maps</title> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> | |
| <script src="https://maps.googleapis.com/maps/api/js?v=3.11&sensor=false" type="text/javascript"></script> | |
| <script type="text/javascript"> | |
| // check DOM Ready | |
| $(document).ready(function() { | |
| // execute | |
| (function() { | |
| // map options | |
| var options = { | |
| zoom: 5, | |
| center: new google.maps.LatLng(39.909736, -98.522109), // centered US | |
| mapTypeId: google.maps.MapTypeId.TERRAIN, | |
| mapTypeControl: false | |
| }; | |
| // init map | |
| var map = new google.maps.Map(document.getElementById('map_canvas'), options); | |
| // NY and CA sample Lat / Lng | |
| var southWest = new google.maps.LatLng(40.744656, -74.005966); | |
| var northEast = new google.maps.LatLng(34.052234, -118.243685); | |
| var lngSpan = northEast.lng() - southWest.lng(); | |
| var latSpan = northEast.lat() - southWest.lat(); | |
| // set multiple marker | |
| for (var i = 0; i < 250; i++) { | |
| // init markers | |
| var marker = new google.maps.Marker({ | |
| position: new google.maps.LatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random()), | |
| map: map, | |
| title: 'Click Me ' + i | |
| }); | |
| // process multiple info windows | |
| (function(marker, i) { | |
| // add click event | |
| google.maps.event.addListener(marker, 'click', function() { | |
| infowindow = new google.maps.InfoWindow({ | |
| content: 'Hello, World!!' | |
| }); | |
| infowindow.open(map, marker); | |
| }); | |
| })(marker, i); | |
| } | |
| })(); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="map_canvas" style="width: 800px; height:500px;"></div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment