Advertisement
Guest User

123132

a guest
May 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.  
  5. <title>Google Maps with pre-set markers and ability to add</title>
  6. <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
  7. </head>
  8. <body>
  9. <div id="map" style="height: 400px; width: 500px;">
  10. </div>
  11. <script type="text/javascript">
  12. var locations = [
  13. ['Zoopark', 43.209857, 27.936020, 4],
  14. ['Palm Beach', 43.202778, 27.924908, 5],
  15. ['Monument', 43.206188, 27.931162, 3],
  16. ['VUM', 43.211926, 27.909179, 2],
  17. ['Hospital', 43.213609, 27.917973, 1]
  18. ];
  19.  
  20. var map = new google.maps.Map(document.getElementById('map'), {
  21. zoom: 13,
  22. center: new google.maps.LatLng(43.2072596, 27.9051413),
  23. mapTypeId: google.maps.MapTypeId.ROADMAP
  24. });
  25.  
  26. var infowindow = new google.maps.InfoWindow();
  27.  
  28. var marker, i;
  29.  
  30. for (i = 0; i < locations.length; i++) {
  31. marker = new google.maps.Marker({
  32. position: new google.maps.LatLng(locations[i][1], locations[i][2]),
  33. map: map
  34. });
  35.  
  36. map.addListener('click', function (e) {
  37. placeMarkerAndPanTo(e.latLng, map);
  38. });
  39. }
  40.  
  41. function placeMarkerAndPanTo(latLng, map) {
  42. var marker = new google.maps.Marker({
  43. position: latLng,
  44. map: map
  45. });
  46. map.panTo(latLng);
  47. }
  48. </script>
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement