Class Geolocation
- java.lang.Object
-
- com.google.gwt.geolocation.client.Geolocation
-
public class Geolocation extends java.lang.Object
Implements the HTML5 Geolocation interface.You can obtain a user's position by first calling
Geolocation.getIfSupported()
Once you have a
Geolocation
, you can request the user's current position by callinggetCurrentPosition(Callback)
orwatchPosition(Callback)
.The first time an application requests the user's position, the browser will prompt the user for permission. If the user grants permission, the browser will locate the user and report it back to your application. If the user declines permission, the callback's
Callback.onFailure(Object)
method will be called with aPositionError
with its code set toPositionError.PERMISSION_DENIED
.Experimental API: This API is still under development and is subject to change.
This may not be supported on all browsers.
- See Also:
- W3C Geolocation API, Dive Into HTML5 - Geolocation
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Geolocation.PositionOptions
Additional options for receiving the user's location.
-
Constructor Summary
Constructors Modifier Constructor Description protected
Geolocation()
Should be instantiated bygetIfSupported()
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearWatch(int watchId)
Stops watching the user's position.void
getCurrentPosition(Callback<Position,PositionError> callback)
Calls the callback with the user's current position.void
getCurrentPosition(Callback<Position,PositionError> callback, Geolocation.PositionOptions options)
Calls the callback with the user's current position, with additional options.static Geolocation
getIfSupported()
Returns aGeolocation
if the browser supports this feature, andnull
otherwise.static boolean
isSupported()
Returnstrue
if the browser supports geolocation.int
watchPosition(Callback<Position,PositionError> callback)
Repeatedly calls the given callback with the user's position, as it changes.int
watchPosition(Callback<Position,PositionError> callback, Geolocation.PositionOptions options)
Repeatedly calls the given callback with the user's position, as it changes, with additional options.
-
-
-
Constructor Detail
-
Geolocation
protected Geolocation()
Should be instantiated bygetIfSupported()
.
-
-
Method Detail
-
getIfSupported
public static Geolocation getIfSupported()
Returns aGeolocation
if the browser supports this feature, andnull
otherwise.
-
isSupported
public static boolean isSupported()
Returnstrue
if the browser supports geolocation.
-
clearWatch
public void clearWatch(int watchId)
Stops watching the user's position.- Parameters:
watchId
- the ID of a position watch as returned by a previous call towatchPosition(Callback)
.
-
getCurrentPosition
public void getCurrentPosition(Callback<Position,PositionError> callback)
Calls the callback with the user's current position.
-
getCurrentPosition
public void getCurrentPosition(Callback<Position,PositionError> callback, Geolocation.PositionOptions options)
Calls the callback with the user's current position, with additional options.
-
watchPosition
public int watchPosition(Callback<Position,PositionError> callback)
Repeatedly calls the given callback with the user's position, as it changes.The frequency of these updates is entirely up to the browser. There is no guarantee that updates will be received at any set interval, but are instead designed to be sent when the user's position changes. This method should be used instead of polling the user's current position.
- Returns:
- the ID of this watch, which can be passed to
clearWatch(int)
to stop watching the user's position.
-
watchPosition
public int watchPosition(Callback<Position,PositionError> callback, Geolocation.PositionOptions options)
Repeatedly calls the given callback with the user's position, as it changes, with additional options.The frequency of these updates is entirely up to the browser. There is no guarantee that updates will be received at any set interval, but are instead designed to be sent when the user's position changes. This method should be used instead of polling the user's current position.
If the browser does not support geolocation, this method will do nothing, and will return -1.
- Returns:
- the ID of this watch, which can be passed to
clearWatch(int)
to stop watching the user's position.
-
-