Skip to content

Promisify getCurrentPosition() #174

Open
@lukewarlow

Description

@lukewarlow

The geolocation API requires use of callbacks rather than being promise based like modern APIs. However, there is room to offer a promise alternative. If we make the callbacks optional, in the case where they're undefined we could return a promise. This was previously done for Notification.requestPermission. This feels like it should be a relatively simple change to make to the API that little bit more intuitive for new developers.

It'll probably never be possible to deprecate the old syntax but at least it would improve newer code.

The only slightly unfortunate bit would be that setting the options param might need to be done like await navigator.geolocation.getCurrentPosition(undefined, undefined, {...}), this also wouldn't be the first time a parameter needs to be set to an empty value, the same is common for history.pushState()

It feels like watchPosition should/could be updated too but I can't think what that would look like given it fires multiple times?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions