Skip to main content

Getting current geo location details of the mobile device using PhoneGap (Cordova)

 The PhoneGap library provide lot of useful functionalities for accessing native mobile features like Camera, Geo location, Voice recorder etc., In this tutorial I am going to collect current Geo location details of the mobile device using Geolocation methods available in PhoneGap (Cordova).
 PhoneGap (Cordova) provides two different methods for getting geo location details. Those are,

            1. geolocation.getCurrentPosition - Returns the current position as Position object.
            2. geolocation.watchPosition - It continuously watch changes of device 's current position.

 The example for above methods are shown here.
navigator.geolocation.watchPosition(geoLocationSuccess,geoLocationError,{timeout : 30000});

function geoLocationSuccess(position) {
 var str = 'Latitude: '          + position.coords.latitude          + '\n' +
           'Longitude: '         + position.coords.longitude         + '\n' +
           'Altitude: '          + position.coords.altitude          + '\n' +
           'Accuracy: '          + position.coords.accuracy          + '\n' +
           'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
           'Heading: '           + position.coords.heading           + '\n' +
           'Speed: '             + position.coords.speed             + '\n' +
           'Timestamp: '         + position.timestamp                + '\n' ;


function geoLocationError(error) {
 alert('code: '    + error.code    + '\n' + 'message: ' + error.message + '\n');
 Here the first parameter indicates your success callback function, second parameter indicates your failure callback and final parameter indicates various options that are provided by PhoneGap (Cordova), those are,
  1. maximumAge - Accept a cached position whose age is no longer than given timeout (in milliseconds)
   2. timeout
   3. enableHighAccuracy - Either true or false.

 There is one more method available for stopping watch position function. The example is show here.
var watchId = navigator.geolocation.watchPosition(geoLocationSuccess,geoLocationError,{ timeout: 30000 });
 You can find more example from PhoneGap (Cordova) documentation.
Hope this help..!


Popular posts from this blog

Ext JS 4 – Creating web page using Ext.container.Viewport class and region propery

The Ext.container.Viewport is used for creating general web page and region property is used for splitting web page into different parts. Ext.container.Viewport is a specialized container represents the viewable area of the application (the browser area). It render itself to the document body, there is no need for providing renderTo property and it automatically sizes itself to size of the browser viewport. The viewport also re-size the child elements based on view area(based on browser width and height). The default layout of the viewport is border layout and we can customize this property according to our requirements. The viewport does not provide any scrolling. If necessary, the child elements(generally panels) within viewport needs to provide a scroll feature by using autoScroll property. See the below example for better understanding. This is Home.js file placed into app/view folder. Ext.define('MyApp.view.Home', { extend : 'Ext.container.Viewport&#

Getting servlet init parameter that is defined in web.xml

1. Create a new dynamic web project using eclipse. 2. Create a one new servlet and include the following code. package com.controller ; import; import javax.servlet .ServletConfig; import javax.servlet .ServletException; import javax.servlet .annotation.WebServlet; import javax.servlet .http.HttpServlet; import javax.servlet .http.HttpServletRequest; import javax.servlet .http.HttpServletResponse; @ WebServlet ( "/LoginController" ) public class LoginController extends HttpServlet {                 private static final long serialVersionUID = 1L;                 public LoginController() {         super ();     }     protected void doPost( HttpServletRequest request, HttpServletResponse response) throws ServletException , IOException {                                 ServletConfig config = getServletConfig ();                                 System.out.println( "Init parameter user nam

Simple Login Application Using Spring MVC and Hibernate – Part 1

 I hope developers working in web application development might hear about MVC architecture. Almost all technologies provide support for MVC based web application development, but the success is based on many factors like reusable of the code, maintenance of the code, future adaption of the code, etc..,  The success of the Spring MVC is “ Open for extension and closed for modification ” principle. Using Spring MVC the developers can easily develop MVC based web application. We don’t need any steep learning curve at the same time we need to know the basics of spring framework and MVC architecture. The Spring MVC consists of following important components. 1. Dispatcher servlet 2. Controller 3. View Resolver 4. Model Spring MVC - Overview  The overall architecture of Spring MVC is shown here.  1. When “Dispatcher Servlet” gets any request from client, it finds the corresponding mapped controller for the request and just dispatches the request to the corresponding contro