fork download
  1. importPackage(java.io);
  2. importPackage(java.lang);
  3.  
  4. // your code goes here
  5. {
  6. let map, infoWindow;
  7.  
  8. function initMap() {
  9. map = new google.maps.Map(document.getElementById("map"), {
  10. center: { lat: -34.397, lng: 150.644 },
  11. zoom: 6,
  12. });
  13. infoWindow = new google.maps.InfoWindow();
  14.  
  15. const locationButton = document.createElement("button");
  16.  
  17. locationButton.textContent = "Pan to Current Location";
  18. locationButton.classList.add("custom-map-control-button");
  19. map.controls[google.maps.ControlPosition.TOP_CENTER].push(locationButton);
  20. locationButton.addEventListener("click", () => {
  21. // Try HTML5 geolocation.
  22. if (navigator.geolocation) {
  23. navigator.geolocation.getCurrentPosition(
  24. (position) => {
  25. const pos = {
  26. lat: position.coords.latitude,
  27. lng: position.coords.longitude,
  28. };
  29.  
  30. infoWindow.setPosition(pos);
  31. infoWindow.setContent("Location found.");
  32. infoWindow.open(map);
  33. map.setCenter(pos);
  34. },
  35. () => {
  36. handleLocationError(true, infoWindow, map.getCenter());
  37. }
  38. );
  39. } else {
  40. // Browser doesn't support Geolocation
  41. handleLocationError(false, infoWindow, map.getCenter());
  42. }
  43. });
  44. }
  45.  
  46. function handleLocationError(browserHasGeolocation, infoWindow, pos) {
  47. infoWindow.setPosition(pos);
  48. infoWindow.setContent(
  49. browserHasGeolocation
  50. ? "Error: The Geolocation service failed."
  51. : "Error: Your browser doesn't support geolocation."
  52. );
  53. infoWindow.open(map);
  54. }
  55.  
  56. }
Success #stdin #stdout 0.4s 44024KB
stdin
Standard input is empty
stdout
Standard output is empty