GetUserLocationRequest RPC
Get user's location
Use cases
- Center map to user's location
Description
This request is used to get user's geolocation. After the geolocation is completed a UserLocationEvent
is triggered where following data is available:
- event.getLon(), tells user geolocation lon coordinate
- event.getLat(), tells user geolocation lat coordinate
Parameters
(* means the parameter is required)
Name | Type | Description | Default value |
---|---|---|---|
centerMap | Boolean | true if map should be centered to user's location | false |
options | Object | Parameters for options-object are listed in the next table |
Parameters for options-object:
Name | Type | Description | Default value |
---|---|---|---|
addToMap | Boolean | If true adds user location to the map. The location (point) is added to vector layer with circle (polygon) expressing the location accuracy. | false |
zoomLevel | Number | used with centerMap to get desired zoom level. Note that overrides accuracy based zooming (enableHighAccuracy). | 6 |
enableHighAccuracy | Boolean | true to receive the best possible location results. If used with centerMap then zoom level is adjusted according to location accuracy. | false |
timeout | Number | Maximum length of time (in milliseconds) the device is allowed to take in order to return a position | 6000 |
maximumAge | Number | Maximum age in milliseconds of a possible cached position. If set to 0 tries to attempt real (not cached) position. | 0 |
Examples
Get user geolocation and center map to user location:
var sb = Oskari.getSandbox();
var reqBuilder = sb.getRequestBuilder('MyLocationPlugin.GetUserLocationRequest');
if (reqBuilder) {
var request = reqBuilder(true);
sb.request('MainMapModule', request);
}
Get user geolocation and not center map to user location:
var sb = Oskari.getSandbox();
var reqBuilder = sb.getRequestBuilder('MyLocationPlugin.GetUserLocationRequest');
if (reqBuilder) {
var request = reqBuilder(false);
sb.request('MainMapModule', request);
}
Get accurate user location, add the location to the map and center the map to the location:
var options = {
enableHighAccuracy: true,
timeout: 15000,
addToMap: true
};
Oskari.getSandbox().postRequestByName('MyLocationPlugin.GetUserLocationRequest', [true, options]);
Remove user location from the map:
Oskari.getSandbox().postRequestByName('MapModulePlugin.RemoveFeaturesFromMapRequest', [null, null, 'USER_LOCATION_LAYER']);
Related api
- UserLocationEvent
- AddFeaturesToMapRequest
- RemoveFeaturesFromMapRequest