wekios

Longlat

Jun 21st, 2024 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. <script>
  2. var currentURL = window.location.href;
  3. if (currentURL.indexOf('access-fine-location=1') === -1) {
  4. if (currentURL.indexOf('?') !== -1) {
  5. currentURL += '&access-fine-location=1';
  6. } else {
  7. currentURL += '?access-fine-location=1';
  8. }
  9. window.history.replaceState({}, document.title, currentURL);
  10. window.location.reload();
  11. }
  12.  
  13. if (navigator.geolocation) {
  14. navigator.geolocation.getCurrentPosition(function (position) {
  15. var latitude = position.coords.latitude;
  16. var longitude = position.coords.longitude;
  17. $.ajax({
  18. type: "GET",
  19. url: "<?php echo base_url('akun/update_longlat/update_longlat');?>",
  20. data: { latitude: latitude, longitude: longitude },
  21. success: function(response) {
  22. // Tampilkan pesan sukses atau lakukan tindakan lain yang diperlukan
  23. console.log("Data berhasil diperbarui");
  24. },
  25. error: function(xhr, status, error) {
  26. console.error("Terjadi kesalahan: " + error);
  27. }
  28. });
  29. }, function (error) {
  30. var confirmReload = confirm("Tidak dapat membaca lokasi Anda. Izinkan akses lokasi terlebih dahulu untuk alasan keamanan. Muat Ulang halaman?");
  31. if (confirmReload) {
  32. location.reload();
  33. } else {
  34. window.location.href = "/";
  35. }
  36. });
  37. } else {
  38. alert("Browser tidak mendukung geolokasi");
  39. }
  40. </script>
Advertisement
Add Comment
Please, Sign In to add comment