Skip to content

Cannot getting location every time in iOS #323

Closed
@muslimmuda15

Description

@muslimmuda15

Sometimes, my app want to getting current location to user but not every time is successful.

Geolocation.getCurrentPosition(
      ({ coords: { latitude, longitude, accuracy } }) => {
        setUserLoc({
          ...userloc,
          latitude,
          longitude,
          accuracy,
        });

        Geolocation.watchPosition(
          ({ coords: { latitude, longitude, accuracy } }) => {
            setUserLoc({
              ...userloc,
              latitude,
              longitude,
              accuracy,
            });
          },
          error => {
            console.log('watch user position: ', error);
            sendToSlack(
              'Error Watching Location on _getCurrentPosition App.js',
              error,
            );
          },
          {
            enableHighAccuracy: true,
            timeout: 20000,
            maximumAge: 5000,
            distanceFilter: 10,
          },
        );
        setTimeout(() => Geolocation.clearWatch(), 300000);
      },
      error => {
        console.log('error accessing location: ', error);
      },
      { enableHighAccuracy: true, timeout: 20000, maximumAge: 5000 },
    );

I think it will be success in first time only. another time it will be error like this:

{
    "code": 3,
    "message": "Unable to fetch location within 20.0s.",
    "PERMISSION_DENIED": 1,
    "POSITION_UNAVAILABLE": 2,
    "TIMEOUT": 3
}

I have set NSLocationAlwaysUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription in my info.plist
Please help

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions