Showing posts with label Location. Show all posts
Showing posts with label Location. Show all posts

Thursday, July 6, 2017

Working with Location and Permissions in JET Hybrid

What if you want to access mobile device location data from JET Hybrid application? This can be achieved with Cordova Geolocation plugin. But you want it to be nicely done and want to make sure application is granted with permission to access location information. Use Cordova Permissions plugin for that.

You could add Cordova plugin to JET app by executing this command:

cordova plugin add 

If this command doesnt work for any reason, you could add plugin information directly into config.xml file (check Geertjan post about the same - Plugging into Devices with Oracle JET on Cordova (Part 1)):




In JS function, before calling location API - we call permissions API to check if app is already granted permission to read location data. In hasPermission method, in case of success - location data is accessed. In case of no permission, request for permission is sent. If request is satisfied - location is accessed (and permission is granted at the same time):


Location data is retrieved through callback:


This is how it works. On very first location access, when permission is not granted yet - we request permission through permission API:


When permission is granted, location is displayed:


Download sample application from GitHub repository - rslocationapp.

Friday, January 11, 2013

ADF Mobile - Device Native Database Access and Usage

This will be a third update for my sample ADF Mobile application. Read about previous versions from here - ADF Mobile - Geo Location Synchronization. This update is focused primarily on device native database access and operations. I'm using located GPS points as data source and populating on device SQL Lite database with locations retrieved from GPS. Logged data review functionality is implemented as well - user can view altitude graph and load logged path as point layer on top of Google Maps.

Added features:

1. ADF Mobile Springboard support demonstrating multiple ADF Task Flow usage and access

2. ADF Mobile UI validation behavior and conditional logic

3. Device native database access and usage

4. Data visualization with ADF DVT components

5. Multi-point layer display on top of Google Maps

6. iPhone right/left swipe actions

Download sample application code - PosLogApp.zip. This sample contains two ADF Task Flows, both of them are loaded using ADF Mobile Springboard - Tracker (logs GPS positions) and Routes (logs and displays route data):


Same as in the previous version - Tracker logs current GPS position. Once Tracker is activated it will log GPS position change continuously until it will be stopped by the user:


In the same ADF Task Flow - Tracker, we can view current GPS position on the Google Maps:


Second ADF Task Flow - Routes allows to enter new route name and date (current date by default). When Start is activated - it will log each GPS position received from the Tracker into native device database until user will stop route logging:


From this screen user have option to view a list of previously recorded routes - Show button:


List is clickable - user can click on the selected route to view information about it. Information about logged GPS position for the selected route is retrieved from database - in the first screen we can see number of GPS positions logged. 1033 positions were logged for this route (maximum is set to be 10000):


We can view logged altitude information for the route - I was driving uphill and then downhill:


Route path itself can be visualized on top of Google Maps from logged GPS points:


If you want to delete logged route, simply swipe to the right and press Delete button:


You want to know about implementation details? All right - here is ADF Task Flow view for the router part:


Page with route name and date is default, next we can view route list and remove routes with refresh through the method call. We can view details - number of logged GPS points, altitude graph and route path constructed from logged GPS points.

Here is the database structure, two tables simple master/detail - ROUTES and POINTS. This script is executed during initial application activation on the device. Basically it creates *.db file with SQL Lite database on the device:


SQL file must be loaded programmatically, from custom lifecycle listener class. We must define this class in adfmf-application.xml file:


Application lifecycle method - start(), will be executed automatically and it will load database structure initially:


Connection to the database is constructed by retrieving reference to the SQL Lite database file on device:


Here you can see code to insert information about new route - regular SQL syntax and PreparedStatement:


This code snipped shows retrieval of GPS logged positions and constructing array of such points (later displayed in altitude graph and path on top of Google Maps):


In order to be able to load Google Maps in ADF Mobile, you must set Google Maps key in adf-config.xml file. Sample application is provided with dummy key, you must set your own:


Xcode Organizer tool displays installed applications on iPhone, I can see database file for my application. Organizer gives option to download application contents together with database file:


We can extract downloaded archive and access database file:


Performance of device native database is pretty good, I recorded around 10000 GPS location points in total - browsing through this dataset and loading is smooth:


Tuesday, December 18, 2012

ADF Mobile - Geo Location Synchronization

Here you can read about ADF Mobile application enabled with geo location features - GPS and Google Maps - ADF Mobile - Geo Location and Google Maps App. I would like to post update for this application where geo location is synchronized automatically, directly updating your position on Google Maps screen. Few minor usability updates are included as well - conditional check for 3G/Wi-Fi network and GPS availability.

Download version 2 for ADF Mobile Geo Location and Google Maps application - ADFMobileGoogleMaps_v2.zip. This update contains code to check if 3G/Wi-Fi and GPS functionality is available - displayed on UI:


Show button is enabled only if 3G/Wi-Fi connection is available, otherwise Google Maps are unaccessible. Start button is enabled only if GPS is available - location will be calculated only with active GPS signal.

Initial position is retrieved from GPS, this position is displayed on the map:


You don't need to switch back and request position correction - keep Google Maps window open, when GPS data will be recalculated - position will be refreshed and displayed automatically:


Go back to initial position screen, you can review synchronized location coordinates there:


3G/Wi-Fi network status is retrieved from ADF Mobile API directly - deviceScope.hardware.networkStatus:


Similar for GPS signal status - deviceScope.hardware.hasGeolocation:


GPS position synchronization is quite straightforward - method from pageFlowScope bean updates center coordinates:


Property Change Support listener is responsible to push data changes to the UI:


Point location layer from ADF Mobile maps component is mapped directly with pageFlowScope bean coordinates data - this allows to reload location point, when location coordinares are changing:


Tuesday, December 11, 2012

ADF Mobile - Geo Location and Google Maps App

Let me describe ADF Mobile application with Google Maps and GPS support. I have implemented this application in few hours, installed on my iPhone and ready to travel - I will not be lost. So, I would like to share source code with you - you can compile and install it on iPhone, iPad or Android.

Main features currently available:

1. Google Maps embedded using ADF Mobile Geographical Map component (8.5.14 How to Create a Geographic Map Component)

2. GPS location update (9.5.8 How to Use the startLocationMonitor Method)

3. GPS location point display

If I will have time, I plan to implement dynamic GPS location point moving on the map as you go and synchronization with on device database. You can download source code for the current version from here - ADFMobileGoogleMaps.zip.

Here is the home screen - Google Maps. Screenshots are taken directly from my iPhone:


User have two options - Reset and Position. I have noticed that sometimes, especially when network connectivity is lost - ADF Mobile application with Maps component may get unresponsive. This is the reason for Reset button - it performs logout and resets application state. Position - it flips Maps display and open GPS control view:


In this screen you can press Start and synchronize Latitude/Longitude for your current position from GPS satellite. Synchronization may take a bit of time, while it becomes accurate - this is the reason for Stop button (to stop synchronization period):


Once position is located, press Back and Google Maps will flip back with a zoom into your position displayed on the map (my real location is displayed here :):


I will walk you know through the technical things. This application contains ADF Task Flow and navigation between Google Maps page and GPS control:


The way how pages are opened on the device (slide, flip) is control by ADF Task Flow navigation case. I have set page transition behavior to be flipLeft:


Google Maps embedded using ADF Mobile Geographical Map component. It sets various properties, such as center, map type, zoom level. ADF Mobile Geographical Map is able to render data layers on top:


My application, renders single point - current position. Position is retrieved from custom bean Data Control (I have defined it myself):


Drag and drop this Data Control on top of ADF Mobile Geographic Map component, JDeveloper generates point data layer automatically from the wizard:


There is getPositions() method responsible to get data about retrieved position (initialized from custom GoogleMapsBean):


GPS action is triggered on the device and data is retrieved using built in ADF Mobile Data Control - Device Features. There is designated method available - startLocationMonitor(boolean, int, String):


GPS method is invoked from the Start button:


One of the parameters - locationListener, it points to the custom listener method. Listener is invoked each time, when GPS position synchronization happens (there is no need to use EL brackets) - method name is static text:


When position is retrieved from GPS and synchronization is stopped - custom Position bean is updated with X/Y:


There is one interesting specific thing related to ADF Mobile - value refresh on the UI. If value is changed in the background, we want to display new value on the UI (but there are no Auto Submit and Partial Triggers in ADF Mobile). Updated value is refreshed on UI using property change support listener invocation from the setter:


Property change support listener declaration: