Privacy prompt on Safari because of browser geolocation

if ( navigator.userAgent.match(/Android/i)
  || navigator.userAgent.match(/webOS/i)
  || navigator.userAgent.match(/iPhone/i)
  || navigator.userAgent.match(/iPad/i)
  || navigator.userAgent.match(/iPod/i)
  || navigator.userAgent.match(/BlackBerry/i)
  ) {

  var success = function(position) {
    var latitude  = position.coords.latitude;
    var longitude = position.coords.longitude;

    if (!navigator.cookieEnabled || getCookie('geolocation')) {
      return false;
    }

    var data = { action: 'geolocate', latitude: latitude, longitude:longitude };
    $.ajax({
        type: 'POST',
        url: '/wp-admin/admin-ajax.php',
        data: data,
        dataType: 'text',
        beforeSend: function (request) {
          request.withCredentials = false;
        }
    });
  }
  

  if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(success, null);
  }
} 

I have this code for browser geolocation, and lately on iOS I keep getting prompted for allowing the tracking of my location on Safari. On other devices like Android, this doesn’t happen. I have it set up as a GTAG and it triggers on every page. Now, I think it is because the backend ajax creates a cookie, but the cookie isn’t set fast enough for the next page load to not trigger the privacy notification, but I was wondering if there’s another way to prevent this notification from showing on Safari.