Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. <div id="map">
  2.  
  3. <script>
  4.  
  5. function initMap()
  6. {
  7. var map = new google.maps.Map(document.getElementById('map'), {
  8. center: {lat: -34.397, lng: 150.644},
  9. zoom: 16
  10. });
  11.  
  12.  
  13. var infoWindow = new google.maps.InfoWindow({map: map});
  14.  
  15. // Try HTML5 geolocation.
  16. if (navigator.geolocation)
  17. {
  18. navigator.geolocation.watchPosition(function(position)
  19.  
  20. {
  21. var pos =
  22. {
  23. lat: position.coords.latitude,
  24. lng: position.coords.longitude
  25. };
  26.  
  27. infoWindow.setPosition(pos);
  28. infoWindow.setContent('Tutaj jesteล›');
  29. map.setCenter(pos);
  30. }, function()
  31. {
  32. handleLocationError(true, infoWindow, map.getCenter());
  33. });
  34. }
  35. else {
  36. // Browser doesn't support Geolocation
  37. handleLocationError(false, infoWindow, map.getCenter());
  38. }
  39. }
  40.  
  41. function handleLocationError(browserHasGeolocation, infoWindow, pos) {
  42. infoWindow.setPosition(pos);
  43. infoWindow.setContent(browserHasGeolocation ?
  44. 'Error: The Geolocation service failed.' :
  45. 'Error: Your browser doesn\'t support geolocation.');
  46. }
  47.  
  48. </script>
  49. <script async defer
  50. src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDZg7lXCatX7_I9nqP5PcUgslu3QKnZXMA&callback=initMap">
  51. </script>
  52.  
  53.  
  54. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement