Class M.LocationManager
Extends
M.Object.
M.LocationManager defines a prototype for managing the user's respectively the
device's location, based on the HTML 5 Geolocation API. The M.LocationManager
provides machanism to retrieve, manage and update a location.
Defined in: location_manager.js.
Constructor Attributes | Constructor Name and Description |
---|---|
Field Attributes | Field Name and Description |
---|---|
This property contains a reference to google maps geocoder class.
|
|
This property specifies whether the M.LocationManager is currently trying to
get a position or not.
|
|
This property contains the date, as an M.Date object, of the last geolocation
call.
|
|
The type of this object.
|
Method Attributes | Method Name and Description |
---|---|
getAddressByLocation(caller, onSuccess, onError, location, getAddressAsComponents)
This method tries to transform a given location as an M.Location object into
a valid address.
|
|
getLocation(caller, onSuccess, onError, options)
This method is used for retrieving the current location.
|
|
getLocationByAddress(caller, onSuccess, onError, address)
This method tries to transform a given address into an M.Location object.
|
Field Detail
{Object}
geoCoder
This property contains a reference to google maps geocoder class. It is used
in combination with the getLocationByAddress() method.
{Boolean}
isGettingLocation
This property specifies whether the M.LocationManager is currently trying to
get a position or not.
{M.Date}
lastLocationUpdate
This property contains the date, as an M.Date object, of the last geolocation
call. It is needed internally to interpret the timeout.
{String}
type
The type of this object.
Method Detail
getAddressByLocation(caller, onSuccess, onError, location, getAddressAsComponents)
This method tries to transform a given location as an M.Location object into
a valid address. This method is based on the google maps api, respectively
on its geocoder class.
If a valid address could be found matching the given location parameter,
the success callback is called with a valid address string as its only
parameter.
Note: If you set the getAddressAsComponents parameter to YES, the address
will be passed to the success callback as an object containing the address'
components. Use this option if you want to put the address together manually.
If no address could be retrieved, the error callback is called, with the
error message as its only parameter. Possible values for this error message
are the following:
- M.LOCATION_GEOCODER_ERROR
- M.LOCATION_GEOCODER_INVALID_REQUEST
- M.LOCATION_GEOCODER_OVER_QUERY_LIMIT
- M.LOCATION_GEOCODER_REQUEST_DENIED
- M.LOCATION_GEOCODER_UNKNOWN_ERROR
- M.LOCATION_GEOCODER_ZERO_RESULTS
- Parameters:
- {Object} caller
- The object, calling this function.
- {Function} onSuccess
- The method to be called after retrieving the address.
- {Function} onError
- The method to be called if retrieving the address went wrong.
- {M.Location} location
- The location to be transformed into an address.
- {Boolean} getAddressAsComponents
- Return the address as an object containing the components.
getLocation(caller, onSuccess, onError, options)
This method is used for retrieving the current location.
The first two parameters define the success and error callbacks. They are
called once the location was retrieved successfully (success callback) or
if it failed (error callback).
The success callback will be called with an M.Location object containing
all the information about the location that was retrieved.
The error callback will be called with one of the following constant
string values:
- PERMISSION_DENIED
- POSITION_UNAVAILABLE
- TIMEOUT
- UNKNOWN_ERROR
- NOT_SUPPORTED
The third parameter, options, can be used to define some parameters for
retrieving the location. These are based on the HTML5 Geolocation API but
extend it:
http://dev.w3.org/geo/api/spec-source.html#position_options_interface
A valid options parameter could look like:
{
enableHighAccuracy: YES,
maximumAge: 600000,
timeout: 0,
accuracy: 100
}
If you do not specify any options, the following default values are taken:
enableHighAccuracy = NO --> turned off, due to better performance
maximumAge = 0 --> always retrieve a new location
timeout = 5000 --> 5 seconds until timeout error
accuracy = 50 --> 50 meters accuracy
- Parameters:
- {Object} caller
- The object, calling this function.
- {Object} onSuccess
- The success callback.
- {Object} onError
- The error callback.
- {Object} options
- The options for retrieving a location.
getLocationByAddress(caller, onSuccess, onError, address)
This method tries to transform a given address into an M.Location object.
This method is based on the google maps api, respectively on its geocoder
class.
If a valid location could be found matching the given address parameter,
the success callback is called with a valid M.Location object as its
only parameter, containing the information about this location.
If no location could be retrieved, the error callback is called, with the
error message as its only parameter. Possible values for this error message
are the following:
- M.LOCATION_GEOCODER_ERROR
- M.LOCATION_GEOCODER_INVALID_REQUEST
- M.LOCATION_GEOCODER_OVER_QUERY_LIMIT
- M.LOCATION_GEOCODER_REQUEST_DENIED
- M.LOCATION_GEOCODER_UNKNOWN_ERROR
- M.LOCATION_GEOCODER_ZERO_RESULTS
- Parameters:
- {Object} caller
- The object, calling this function.
- {Function} onSuccess
- The method to be called after retrieving the location.
- {Function} onError
- The method to be called if retrieving the location went wrong.
- {String} address
- The address to be transformed into an M.Location object.