Saturday, 14 May 2016

Geolocation plugin in Phonegap

Geolocation: 
           This provides information about the devices's location such as latitude and longitude based on devices's Global Positioning System(GPS) sensor and inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses.
          But there is no guarantee that the API will return actual position of the device.

First, need to install the plugin in your project directory by using below command:

>> phonegap plugin add org.apache.cordova.geolocation


3 methods:

1. geolocation.getCurrentPosition
2. geolocation.watchPosition
3. geolocation.clearWatch

1. geolocation.getCurrentPosition: It is an asynchronous function. It returns the devices's current position to the geolocationSuccess callback with a Position object as a parameter. If there is an error, the geolocationError is passed with PositionError object.

navigator.geolocation.getCurrentPosition(geolocationSuccess,
                                                                   geolocationError,
                                                                   geolocationOptions);

geolocatoinOptions ---> For extra options like timeout

Sample Example:


navigator.geolocation.getCurrentPosition(geolocationSuccess,geolocationError);

function geolocationSuccess(position)
{
        alert("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.coords.timestamp + "\n" + 
               );
}

function geolocationError(positionError)
{
         alert("Error Code" + positionError.code + "\n" + 
                 "Error Message" + positionError.message + "\n" + 
                );
}

2. geolocation.watchPosition: It is an asynchronous function. It returns the current position of the device when a change in position detected. When the device found new location, the geolocationSuccess callback returns position object as a parameter. If there is an error, the geolocationError callback executes with a positionError object as the parameter.


var watchId = navigator.geolocation.watchPosition(geolocationSuccess,
                                                                                   geolocationError,
                                                                                  geolocationOptions);

Note: You can write above example for this, the only difference is above geolocationSuccess calls one time, but in this whenever the position changes.

3. geolocation.clearWatch: It stops watching whenever device changes by using watchId  mentioned in second method.

navigator.geolocation.clearWatch(watchId);





Please let me know any help from Phonegap side.

Wednesday, 4 May 2016

All commands of Phonegap CLI

To create app:
First, go to the directory where you want to create the app and execute below command in cmd.

>> phonegap create PS com.phonegap.phonegapsolutions PhonegapSolutions

PS ---> This is the directory of the project. This is mandatory
com.phonegap.phonegapsolutions ---> This is optional, we can edit this later in config.xml file. Using this we can identify the project.
PhonegapSolutions ---> This is the title for the project. This also optional and you can edit in config.xml file.

To add platforms:
Go to the project directory and execute below commands. You can add platforms according to your need.

>> phonegap platform add android
>> phonegap platform add ios
>> phonegap platform add windows
>> phonegap platform add blackberry10

You can check installed platforms by using below command:
>> phonegap platfomrs (or) phonegap platform ls

You can remove added platforms by using below command:
>> phonegap platform remove android (or) phonegap platform rm android
>> phonegap platform remove ios (or) phonegap platform rm ios

To build app:
Using below command you can build all platforms sequentially:
>> phonegap build

You can limit the build to specified platform:
>> phonegap build android (or) phonegap prepare android (or) phonegap compile android
>> phonegap build ios (or) phonegap prepare ios (or) phonegap compile ios

To test app:
You can test the app in emulator using below command. This command can do both building and emulating the app.

>> phonegap emulate android (or) phonegap run android

To add plugin features:
We need to add plugins for extra features to our project. Some of the plugin commands are below:

>> phonegap plugin add org.apache.cordova.device ---> To get basic device information
>> phonegap plugin add org.apache.cordova.network-information --> For network information
>> phonegap plugin add org.apache.cordova.battery-status ---> To get status of the battery
>> phonegap plugin add org.apache.cordova.device-motion ---> To get motion of the device
>> phonegap plugin add org.apache.cordova.device-orientation ---> To get orientation of the device
>> phonegap plugin add org.apache.cordova.geolocation --->To get geolocation of device
>> phonegap plugin add org.apache.cordova.camera ---> Get access to camera

For media playback and capture:
>> phonegap plugin add org.apache.cordova.media-capture
>> phonegap plugin add org.apache.cordova.media

To get access to file on device or network:
>> phonegap plugin add org.apache.cordova.file
>> phonegap plugin add org.apache.cordova.file-transfer

To get notifications via dialog box or vibration:
>> phonegap plugin add org.apache.cordova.dialogs
>> phonegap plugin add org.apache.cordova.vibration

>> phonegap plugin add org.apache.cordova.contacts ---> To get access to contacts
>> phonegap plugin add org.apache.cordova.globalization ---> For globalization
>> phonegap plugin add org.apache.cordova.splashscreen ---> To get splashscreen
>> phonegap plugin add org.apache.cordova.inappbrowser ---> To open new browser

You can check installed plugins by using below command:
>> phonegap plugin ls

To remove added plugins:
>> phonegap plugin remove org.apache.cordova.inappbrowser

You can add or remove multiple plugins by specifying plugins with space like below:
>> phonegap plugin add org.apache.cordova.inappbrowser org.apache.cordova.splashscreen
>> phonegap plugin remove org.apache.cordova.inappbrowser org.apache.cordova.splashscreen

Help Commands:
Below help command will display all available commands of phonegap and their syntax.
>> phonegap help (or) phonegap

You also can get help on specific command  like below
>> phonegap run help

Below command will produce all information about app such as installed platforms, plugins, versions of SDK of each platform, versions CLI and node.js

>> phonegap info

Commands to update Phonegap and Project:

>> npm update -g phonegap                     ---> To update phonegap
>> phonegap platform update android     ---> To update android




Let me know any help from phonegap side.


Monday, 2 May 2016

How to install Phonegap CLI in Windows Platform?

To getting start with Phonegap CLI, follow below steps:

1. First, need to install node.js. It is a JavaScript runtime to build your JavaScript code behind the project.

2. Install Phonegap CLI using below command in cmd
             >> npm install -g phonegap

You can check installtion of phonegap by typing phonegap in cmd and pressing enter button. It should show some helpful info about phonegap command.

3. If you already have android sdk, fine. Otherwise you can install it from this link Android sdk.

4. Set environment system variables path as
                       <sdk-path>\platform-tools
                       <sdk-path>\tools

You can check step 4 by typing android in cmd and pressing enter button. It should open SDK Manager

5. Then create one android virtual device(avd) using AVD Manager to emulate the project.

Now, it's done the installation of Phonegap CLI, Android SDK and Android AVD.

Useful commands:

>> phonegap create hello com.phonegap.helloworld HelloWorld    ---> To create phonegap project

>> phonegap platform add android            ---> To add andorid platform

>> phonegap run android                           ---> To build and run project





Let me know any help from Phonegap side

Sunday, 1 May 2016

How to work with Phonegap Desktop App?

After completion of the installation process of Phonegap Desktop App, you are able to create one new project using that application.

Project Creation:
1. Open Phonegap Desktop Application shortcut file and click on + button which is over in the left pane of the application. You can see two options over there one is Create new Phonegap project and another one is Open existing Phonegap project. Click on 1st option to create new project.








































2. Select your project path, write Name of the project and ID of the project. Then click on Create Project button.









































Your project is created now.

Note: You can open existed projects by using second option(Open existing Phonegap Project) of the step 1.


Delete created project:
Click on - button which is over in the left pane of the application home page.








































You can delete the created project by clicking on that red cross symbol.

Run a project:
       To run a project, click on arrow button which is over in the right side of the created project









































Now, you can observe that footer is going to turn like green color saying something about ip and port. Using that ip you can connect to this project and preview in your mobile using Phonegap Developer App. You can stop the project by clicking on stop symbol under run arrow button.








































You can change the port of the running server usgin settings button which is over in the left pane of the app.








































This is about Phonegap Desktop App. If you want to build, to get APK file and to run project on emulator, you need to install Phonegap CLI mode also. You can see post here How to install Phonegap CLI in Windows Platform?



Let me know any help from Phonegap side.

How to install Phonegap Desktop App in Windows platform?

1. First, download the latest file from this link Windows Installer.

2. Go to that downloaded folder and double click on that installer file then it will prompt like this. Click on Next button

3. Accept license agreement

4. Select destination folder and click on Next button


 5. Select start menu folder and click on Next button










 6. Click on Install button to begin installation


7. Click on Finish button to finish the installation


Installation finished. You can see the post here How to work with Phonegap Desktop App?



Let me know any help from Phonegap side