Skip to content

[Bug]: Location returns cached location #744

@r-smolonskij

Description

@r-smolonskij

Telegram Application

Telegram for Android

Describe the Bug

Hey there. 👋
I have Telegram Web App built on Nuxt3. We are using Telegram's LocationManager to retrieve location of the user when they click specific button.
The issue is that in many cases Telegram does not return new location but instead returns cached location.
If I was purely using WEB Geolocation I could set maximumAge: 0 and enableHighAccuracy: true which would resolve the issue and would give me new data every time. But I couldn't find anything like that for Telegram.

Reaching out here to ask for help how to resolve that!? Anyone here knows fix?

I have tried it with @telegram-apps/sdk-vue and also "@telegram-apps/bridge", both returned cached locations.

Implementation with @telegram-apps/bridge

import { request } from "@telegram-apps/bridge";

export const requestLocation = async () => {
  try {
    const response = await request(
      "web_app_check_location",
      "location_checked"
    );
    if (!response.available || !response.access_granted) {
      alert(JSON.stringify(response));
      return;
    }
    const location = await request(
      "web_app_request_location",
      "location_requested"
    );
    return location;
  } catch (error) {
    alert(JSON.stringify(error));
  }
};

Implementation with @telegram-apps/sdk-vue

import {
  locationManager as LManager
} from "@telegram-apps/sdk-vue";

const mountLocationManager = async () => {
  if (LManager.mount.isAvailable()) {
    try {
      if (LManager.isMounted()) {
        await LManager.unmount();
        await new Promise((resolve) => setTimeout(resolve, 200)); // small delay
      }
      await LManager.mount();
    } catch (err) {
      console.error(err);
    }
  }
};

export const requestLocation = async (): Promise<unknown | null> => {
  try {
    await mountLocationManager();
    if (LManager.requestLocation.isAvailable()) {
      const locationData = await LManager.requestLocation();
      if (locationData.latitude) {
        const { latitude, longitude } = locationData;
        return { latitude, longitude };
      }
      return null;
    } else {
      return null;
    }
  } catch (error) {
    console.error(error);
    return null;
  }
};

To Reproduce

Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected Behavior

Return new location instead of cached location

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions