Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass the function to get coordinates in .locate() #7296

Open
Nisgrak opened this issue Sep 29, 2020 · 0 comments
Open

Allow to pass the function to get coordinates in .locate() #7296

Nisgrak opened this issue Sep 29, 2020 · 0 comments
Labels
compatibility Cross-browser/device/environment compatibility feature

Comments

@Nisgrak
Copy link

Nisgrak commented Sep 29, 2020

Is your feature request related to a problem? Please describe.
I'm making a web app with Capacitor and https didn't work in iOS so can't use navigator.geolocation.getCurrentPosition() but Capacitor exposes that in his modules, so I can get the coordinates, but not with the function leaflet uses

Describe the solution you'd like
A new option in locate config to overwrite the function to read the coordinates in

Leaflet/src/map/Map.js

Lines 660 to 665 in bdd7ebf

if (options.watch) {
this._locationWatchId =
navigator.geolocation.watchPosition(onResponse, onError, options);
} else {
navigator.geolocation.getCurrentPosition(onResponse, onError, options);
}

Describe alternatives you've considered
I try to use https in iOS Capacitor but in the issues the devs say that didn't work anyways

Additional context
I think that the code would be something like this:

this.map.locate({
    getCoordinates: async (onResponse, onError, options) => {
        return await Geolocation.getCurrentPosition(); // Return the same as navigator.geolocation.getCurrentPosition()
    }
})

if (options.getCoordinates) {
    if (options.watch) {
        this._locationWatchId = options.getCoordinates(options);

    } else {
        try {
            var pos = await options.getCoordinates(options);
            onResponse(pos);

        } catch (error) {
            onError(error);

        }
    }
} else {
    if (options.watch) {
        this._locationWatchId =
            navigator.geolocation.watchPosition(onResponse, onError, options);

    } else {
        navigator.geolocation.getCurrentPosition(onResponse, onError, options);

    }
}
@Nisgrak Nisgrak changed the title Allow to pass the coordinates in .locate() Allow to pass the function to get coordinates in .locate() Sep 30, 2020
@Malvoz Malvoz added the compatibility Cross-browser/device/environment compatibility label Apr 7, 2022
@Malvoz Malvoz added the feature label Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Cross-browser/device/environment compatibility feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants