Altova MobileTogether Designer

Reading and Sharing the Geolocation

Home Prev Top Next

The top part of the design (screenshot below) displays the geolocation data of the device.

MTDTutGeolocGeodata

The top row consists of the Send button and four labels. The two labels highlighted in blue use static text for their label text (Latitude: and Longitude: ). The other two labels have page source links to the latitude and longitude nodes of the $MT_GEOLOCATION tree: $MT_GEOLOCATION/Root/Location/@Latitude and $MT_GEOLOCATION/Root/Location/@Longitude. As a result, whenever, these nodes are updated, the two labels will also be updated.

The second and third rows contain a total of four Edit Fields. These controls are page source links, respectively, to the first four AddressLine nodes of the $MT_GEOLOCATION tree: $MT_GEOLOCATION/Root/Address/AddressLine. All four edit fields will therefore also be updated when the corresponding nodes are updated.

This leaves the Send button. The button's OnButtonClicked action defines all the actions required to: (i) obtain and display the geolocation of the mobile device, and (ii) to share the geolocation via the device's apps. The Send button's actions are described below.

 

Note:The $MT_GEOLOCATION tree is automatically added as a page source of the page when the Start/Stop Geo Tracking action or the Read Geo Data action is added to design.

 

Send-button actions

Double-click the Actions dialog icon at the top left of the Send button (see screenshot above) to open the button's Actions dialog (screenshot below).

MTDTutGeolocGeodataSend

The following actions have been defined for the OnButtonClicked event. This means that when the button is clicked, all the actions defined for it will be executed, one after the other, in the order defined.

 

Start Geolocation Tracking to start the tracking of the device. We have defined an XML file to be used as a simulation file. This file is called LondonLocations.xml, and it should be located in the same folder as the MTD file. Since actual geolocation data is not available during simulations on the desktop running MobileTogether Designer, the data in this file is used as a substitute for the actual geolocation data of a mobile device.

The Read Geo Data action takes the geolocation data provided by the tracking and structures it into the XML format of the $MT_GEOLOCATION tree. In our definition of the action, we have specified that data from both the Location element as well as the Address element should be written to the $MT_GEOLOCATION tree. In real life situations, this data would be the Location and Address data of the mobile device. In the case of our simulations, the Location and Address data is taken from the file LondonLocations.xml. When the $MT_GEOLOCATION tree is updated with the new geolocation data, all the labels and edit fields in the solution will automatically display the updated data. This is because of the page source links between the controls and the updated nodes.

The Share action creates a text message with a title of My Location. the content of the message is the value of the $MT_GEOLOCATION/Root/Location/@Geolocation attribute (which is a concatenation of the latitude and longitude values). In real life execution, the Share action will open the mobile device's Share menu, thus enabling the end user to send the device's current geolocation to contacts via any of the device's Share apps. In the simulation, a message box containing the title and content of the messages is displayed (see screenshot below).

MTDTutGeolocSimShareMsg

For more detailed information, see the description of the respective actions.

 

© 2018-2024 Altova GmbH