3

This works on Safari on Mac OS X, and Chrome on both Mac OS X and Android. But it fails on Safari on iOS (tested on both iPhone 8 and iPad).

if (navigator.geolocation) {
  alert('geolocation OK');
  navigator.geolocation.getCurrentPosition(function(position) {
    alert('getCurrentPosition OK');
    BaseLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    initMap();
  });
}

I am getting the alert geolocation OK, but the second getCurrentPosition OK doesn't show on iOS and initMap is never called.

How do I debug, I do not have a USB cable to connect my iPhone or iPad.

Alfred Balle
  • 1,135
  • 4
  • 16
  • 32

1 Answers1

0

I know this is an old post, but we had some major issues at work with navigator.geolocation.getCurrentPosition() in standalone mode in iOS Safari.

I posted a more comprehensive answer here but the general gist of our final code was:

export function getUserPosition(): Promise<GeolocationPosition> {
  const promiseArray = [];

  if (navigator.standalone) {
    promiseArray.push(
      new Promise((resolve, reject) => {
        const wait = setTimeout(() => {
          clearTimeout(wait);
          reject('Location has timed out');
        }, 4000);
      })
    );
  }

  const getCurrentPositionPromise = new Promise((resolve, reject) => {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(resolve, reject, {
        timeout: 5000,
        maximumAge: 2000,
        enableHighAccuracy: true,
      });
    } else {
      reject(new Error('Browser does not support geolocation!'));
    }
  });

  promiseArray.push(getCurrentPositionPromise);

  return Promise.race(promiseArray) as Promise<GeolocationPosition>;
}
Jamie
  • 3,105
  • 1
  • 25
  • 35