Warning: The
Maps external object is newer than the Geolocation external object. Many of the methods and properties provided by both external objects are similar. The difference consists in the fact that the
Maps external object uses the
Geography data type while the Geolocation external object uses the Geolocation domain (which is deprecated). In addition, the Maps external object includes more functionalities. The use of the Maps external object and the Geography data type is highly recommended. Therefore, to solve this feature, read
HowTo: Use GetLocation method from Maps external object.
Every day, the postal service employee has to deliver many letters, and for this reason he needs to know the places near his delivery points, based on his current location.
To this end, create a Transaction where to store all of the post office's requirements in table that will be created. In addition, a Native Moblile application will display, in a map, the delivery points (using the Maps Control Type) and its current position (using the GetMyLocation method of the Geolocation external object).
Below is a detailed description of the four steps required for this implementation. See in detail the four steps to perform this implementation.
First, create the Transaction object that will be used to store all of the Post Office's requirements.
POReqId * // Numeric(10.00) Autonumber property = True
POREqAddress // Character(500): Address or description
POReqLoc // Geolocation: Latitude, Longitude
POReqDeliver // Boolean
PoReqPin // Image: Image Icon
2. Create a Menu object and an Entry Panel (WWPostNear) based on WorkWithdevicesPostOffice
Apply the Work With pattern (WorkWithDevicesPostOffice will be created) and set:
- List/Grid/Control Type = Maps
- List/Grid/Location Attribute = POReqLoc
- List/Grid/Pin image Attribute = POReqPin
Create a Menu object and add WorkWithDevicesPostOffice item. (For further information see Applying Work With Pattern).
Create the "GetMyLoc" action in the WorkWithDevicesPostOffice List object, and invoke the GetMyLocation method.
To create the action, click on List node, go to Events and select the "Add" action button (GetMyLoc). To invoke the GetMyLocation method, go to Events and write the following code:
Event 'GetMyloc'
&GetMyLocation = Geolocation.GetMyLocation(0,0,false)
EndEvent
// where:
// &GetMyLocation is based on GeoLocationInfo Data type,
// Geolocation is not a variable, it's an external object's static reference
Note: The GetMyLocation method must be invoked from an action; it can’t be invoked from a procedure because this method is executed on the device side.
Create a nested action and from there invoke the procedure that stores “my position” in the database (the Composite command clause must be used to synchronically trigger nested actions). This action sets the GeoLocationInfo parameter, which is the result of invoking the GetMyLocation method mentioned above. It will be similar to the following:
Event 'GetMyloc'
Composite
&GetMyLocation = Geolocation.GetMyLocation(0,0,false)
StoreMyLocation(&GetMyLocation)
EndComposite
EndEvent
The StoreMyLocation procedure is similar to the following:
parm(&GetMyLocation); //Important: the name of the parmeter MUST Be the same of the Method which is invoked
new
POReqAddress = 'I am Here'
POReqLoc = &GetMyLocation.Location
POReqDeliver = false
PoReqPin.FromImage(here)
endnew
Create a nested action to refresh the data, writing code similar to this: SD Actions.Refresh().
In the end it will look as follows:
When executing, it looks like:
A complete Knowledge Base of these examples is available here.
Geolocation - Show points near me
Geolocation - Showing My Location
Geolocation external object