Class Geolocation

java.lang.Object
org.vaadin.firitin.geolocation.Geolocation

@Deprecated(since="3.6", forRemoval=true) public class Geolocation extends Object
Deprecated, for removal: This API element is subject to removal in a future version.
Vaadin 25.2 ships a native equivalent, com.vaadin.flow.component.geolocation.Geolocation. Prefer it: Geolocation.watchPosition(component) returns a GeolocationWatcher that is bound to the component and auto-stopped on detach (no manual cancel()), and it offers a one-shot getPosition(...), a GeolocationOptions.builder() and Signal-based reads. Note the migration is not drop-in: position data is exposed as a record (position.coords().longitude()) instead of getters.
A helper class to detect the geographical position of the end users.

This class uses the Geolocation API in the browser to detect the position of the user. The API mimics the JS counterpart.

Note that the availability and quality of the position data can vary a lot. Users can decline the geolocation request in the browser altogether, but developers can also affect the settings using GeolocationOptions.

Author:
mstahv
  • Constructor Details

    • Geolocation

      public Geolocation()
      Deprecated, for removal: This API element is subject to removal in a future version.
  • Method Details

    • watchPosition

      public static Geolocation watchPosition(Geolocation.UpdateListener listener, Geolocation.ErrorListener errorListener)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Starts to repeatedly watch the geolocation of the device and notifies listener with the data.
      Parameters:
      listener - the listener called on succesful geolocation request
      errorListener - the listener called in case the request failed (e.g. user declined the request in the browser)
      Returns:
      a Geolocation instance that can be used to cancel requesting the data
    • watchPosition

      public static Geolocation watchPosition(Geolocation.UpdateListener listener, Geolocation.ErrorListener errorListener, GeolocationOptions options)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Starts to repeatedly watch the geolocation of the device and notifies listener with the data.
      Parameters:
      listener - the listener called on succesful geolocation request
      errorListener - the listener called in case the request failed (e.g. user declined the request in the browser)
      options - options for the geolocation request
      Returns:
      a Geolocation instance that can be used to cancel requesting the data
    • watchPosition

      public static Geolocation watchPosition(com.vaadin.flow.component.UI ui, Geolocation.UpdateListener listener, Geolocation.ErrorListener errorListener, GeolocationOptions options)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Starts to repeatedly watch the geolocation of the device and notifies listener with the data.
      Parameters:
      ui - the UI in which context the geolocation request is to be executed
      listener - the listener called on succesful geolocation request
      errorListener - the listener called in case the request failed (e.g. user declined the request in the browser)
      options - options for the geolocation request
      Returns:
      a Geolocation instance that can be used to cancel requesting the data
    • getCurrentPosition

      public static void getCurrentPosition(Geolocation.UpdateListener listener, Geolocation.ErrorListener errorListener, GeolocationOptions options)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Determines the device's current location once and notifies listener with the data.
      Parameters:
      listener - the listener called on succesful geolocation request
      errorListener - the listener called in case the request failed (e.g. user declined the request in the browser)
      options - options for the geolocation request
    • getCurrentPosition

      public static void getCurrentPosition(com.vaadin.flow.component.UI ui, Geolocation.UpdateListener listener, Geolocation.ErrorListener errorListener, GeolocationOptions options)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Determines the device's current location once and notifies listener with the data.
      Parameters:
      ui - the UI in which context the geolocation request is to be executed
      listener - the listener called on succesful geolocation request
      errorListener - the listener called in case the request failed (e.g. user declined the request in the browser)
      options - options for the geolocation request
    • getCurrentPosition

      public static void getCurrentPosition(Geolocation.UpdateListener listener, Geolocation.ErrorListener errorListener)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Determines the device's current location once and notifies listener with the data.
      Parameters:
      listener - the listener called on succesful geolocation request
      errorListener - the listener called in case the request failed (e.g. user declined the request in the browser)
    • cancel

      public void cancel()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Stops polling the listeners with the new geolocation data.