script.js 879 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var findMeButton = $('.find-me');
  2. // Check if the browser has support for the Geolocation API
  3. if (!navigator.geolocation) {
  4. findMeButton.addClass("disabled");
  5. $('.no-browser-support').addClass("visible");
  6. } else {
  7. findMeButton.on('click', function(e) {
  8. e.preventDefault();
  9. navigator.geolocation.getCurrentPosition(function(position) {
  10. // Get the coordinates of the current possition.
  11. var lat = position.coords.latitude;
  12. var lng = position.coords.longitude;
  13. $('.latitude').text(lat.toFixed(3));
  14. $('.longitude').text(lng.toFixed(3));
  15. $('.coordinates').addClass('visible');
  16. // Create a new map and place a marker at the device location.
  17. var map = new GMaps({
  18. el: '#map',
  19. lat: lat,
  20. lng: lng
  21. });
  22. map.addMarker({
  23. lat: lat,
  24. lng: lng
  25. });
  26. });
  27. });
  28. }