Class AjaxGeolocationBehavior

All Implemented Interfaces:
Serializable, IComponentAwareEventSink, IRequestListener, IComponentAwareHeaderContributor, IClusterable

public abstract class AjaxGeolocationBehavior extends AbstractDefaultAjaxBehavior
See Also:
  • Constructor Details

    • AjaxGeolocationBehavior

      public AjaxGeolocationBehavior()
  • Method Details

    • respond

      protected void respond(AjaxRequestTarget target)
      Specified by:
      respond in class AbstractDefaultAjaxBehavior
    • onGeoAvailable

      protected abstract void onGeoAvailable(AjaxRequestTarget target, String latitude, String longitude)
    • onNotAvailable

      protected void onNotAvailable(AjaxRequestTarget target, String errorCode, String errorMessage)
      Override this method if you want to react on the event that no geolocation could be determined.
      Parameters:
      target - the AjaxRequestTarget
      errorCode - the numeric code for the reason no geolocation could be determined as specified by the W3C (@see http://dev.w3.org/geo/api/spec-source.html#position_error_interface).
      "1" indicates a "permission denied"
      "2" indicates that the position could not be determined
      "3" indicates a timeout
      errorMessage - describes the details. Primarily for debugging purposes
    • onBind

      protected void onBind()
      Overrides:
      onBind in class AbstractDefaultAjaxBehavior
    • renderHead

      public void renderHead(Component c, IHeaderResponse response)
      Specified by:
      renderHead in interface IComponentAwareHeaderContributor
      Overrides:
      renderHead in class AbstractDefaultAjaxBehavior
    • getTimeout

      public int getTimeout()
      Returns the current timeout in milliseconds.
      See Also:
    • setTimeout

      public void setTimeout(int timeout)
      Sets the timeout in milliseconds. If the user is ignoring the request for sharing his location or postpones his decision (in Firefox the "Not now" option) no callback method is called. This is intended by design (see https://bugzilla.mozilla.org/show_bug.cgi?id=650247 ). For those cases we can set a timeout. After the specified amount of time the onNotAvailable(org.apache.wicket.ajax.AjaxRequestTarget,java.lang.String,java.lang.String) method is called, passing a "3" as an error code. The specification (http://dev.w3.org/geo/api/spec-source.html#position_error_interface) defines also a timeout attribute: "The length of time specified by the timeout property has elapsed before the implementation could successfully acquire a new Position object." So it applies only for the case the user grants permission to share his location and is NOT the timeout which is set in this method! It MIGHT happen that the determination of the location takes a bit longer, even though the user granted permission to share his location. In this case first onNotAvailable(org.apache.wicket.ajax.AjaxRequestTarget, java.lang.String, java.lang.String) will be called and as soon as the location could be obtained onGeoAvailable(org.apache.wicket.ajax.AjaxRequestTarget, java.lang.String, java.lang.String) will be called. So don't set the timeout too low. The default timeout is set to 10 seconds.