How to determine and watch location of the current user
It may be necessary for your application to determine the location of the current user – for example, if it needs to calculate users or places of interest closest to the current user.
The location of the current user can be determined by using the MOBILE GET LOCATION INTO
action of the Rule Language. Before you can use this action, though, you need to add a special MGeoLocation object into your business space version. To do this right click on the Business Objects in the Configuration Elements Tree and select the Add GeoLocation
object from the popup menu. Then you can use the MOBILE GET LOCATION INTO
action that will write the current longitude and latitude (and some other values) of the current user into the attributes of the MGeoLocation
object. For example:
CREATE MGeoLocation MOBILE GET LOCATION INTO MGeoLocation DISPLAY MESSAGE 'Longitude is ' + MobileGeoLocation.Longitude
You can use this instance of the MobileGeoLocation
object to display the location on a GoogleMap, for example. Or you can provide rules that calculate the distance between geo locations using the DISTANCE
function.
You can also record changes to the user location. This can be done by using the MOBILE START LOCATION WATCH INTO
action. This action will automatically track changes to the user location and write them into the provided instance of the MobileGeoLocation object. For example:
MOBILE START LOCATION WATCH INTO MGeoLocation
Tracking changes can be stopped using the MOBILE STOP LOCATION WATCH FROM
action. For example:
MOBILE STOP LOCATION WATCH FROM MGeoLocation
Note that all geo location actions can be used in both browser-based mobile and non-mobile applications as well as in native mobile applications.