>
Class & methods for getting j2me location coordina...
Welcome, Guest

by dhanendra on Saturday, 22 November 2008
Class & methods for getting j2me location coordinates


/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package utils; import javax.microedition.lcdui.Alert; import javax.microedition.location.Location; import javax.microedition.location.LocationListener; import javax.microedition.location.LocationProvider; import javax.microedition.location.QualifiedCoordinates; import main.Mainform; public class GPSCord implements LocationListener { int timeout = 1; int wait=100; long startTime; long fixTime; Mainform m; private LocationProvider provider; private int gpsState = 0; private int newtimer=utility.locationUpdationWaitTime*60; void StartGPS() { startTime = System.currentTimeMillis(); try { if (provider == null) { provider = LocationProvider.getInstance(null); provider.setLocationListener(this, newtimer, 30, 30); //provider.getLocation(1); } } catch (Exception e) { //Dialog.show("error", "sleep", "OK", null); } } void showTime() { long time = System.currentTimeMillis(); } void handleLocation(Location loc) { if (loc.isValid()) { fixTime = System.currentTimeMillis(); QualifiedCoordinates coord = loc.getQualifiedCoordinates(); // can call the caller class method to get these co-ordinates } } } public void locationUpdated(LocationProvider p, final Location loc) { new Thread() { public void run() { showTime(); handleLocation(loc); } } .start(); } public void providerStateChanged(LocationProvider p, int state) {} class Timer extends Thread { void waitForDeadline(int period) { period *= 1000; try { Thread.sleep(period); } catch (InterruptedException e) { } } void getLocation(int timeout) { try { //mainForm.append("getLocation("+timeout+")...n"); Location loc = provider.getLocation(timeout); showTime(); handleLocation(loc); } catch (Exception e) { showTime(); //mainForm.append("Exception " + e + "n"); return; } } public void run() { //mainForm.append("Timer startedn"); while (true) { switch (gpsState) { case 0: // idle try { Thread.sleep(100000); //Dialog.show("time", "sleep", "OK", null); } catch (InterruptedException e) {} break; case 1: // sampling //Dialog.show("wait", "sleep", "OK", null); waitForDeadline(wait); getLocation(timeout); break; } } } }; Timer timer; void stop() { if (provider != null) provider.setLocationListener(null, -1, -1, -1); gpsState = 0; } void reset(){ if (provider != null) { provider.reset(); } } void synched(){ stop(); gpsState = 1; } void asynched(){ stop(); if (provider != null) provider.setLocationListener(this, timeout + wait, timeout, -1); } // Mainform class is the class from where this class is called public GPSCord(Mainform mainfrm) { this.m=mainfrm; if (timer == null) { //timer = new Timer(); timer.start(); } StartGPS(); } }



Blogger Image
My Blog Title

Product Engineering, software engineering company, Product Development, Product Migration, Product Re-engineering, Product Maintenance, Product Testing Commercial Application Development, Business Software development, commercial software for startups, Application Support and Maintenance, software testing Product Maintenance, Outsource product maintenance, product support and maintenance Product Migration, Product Re-engineering, product re-engineering services Product Research, Product Engineering, UI Prototyping Services Software Testing Services, Quality Assurance services, professional software testers, Load Testing, Functional Testing, Cross Platform, Browser Testing, Test Automation, Testing Tools, software quality analysis Functional Testing Services, software quality analysis, Software Testing Services, Application Testing Services, Functional Testing Types Automated Testing, Automated Testing Services, automation testing, test script development, Automation Test Tools, outsource automation testing Load Testing, Performance Testing Services, Load Testing Tools Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Benefits of IT Outsourcing, Offshore Software Development companies, offshore software development firms Outsource planning, IT outsourcing, IT development services, offshore IT companies, offshore software development Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering Offshore Software Development, Outsource software services, offshore outsourcing services, offshore software development services, IT outsourcing services, software quality assurance services, Offshore IT services, Custom Application Development Services, Offshore Product Engineering