BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-30-2008, 04:03 AM   #1 (permalink)
New Member
 
Join Date: Sep 2008
Model: 9000
PIN: N/A
Carrier: dhfkdhf
Posts: 12
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default BlackBerry Tracking problem

Please Login to Remove!

Hi All,

I am working on BlackBerry 9000. I created one application on Blackberry Tracker by using Timer. the purpose of the application is when i ll track any place in map, the longitude/latitude will be displayed on screen.
But , the map screen is not displaying . what is the problem?
can you reply me? I am posting my code. Please check it.

Please reply me as soon as possible. I am in hurry.

/*Gps.java:*/

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package com.rim.track;

import net.rim.blackberry.api.maps.MapView;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
//
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
//

final class Gps extends UiApplication{

private static MapView _mv = new MapView();
public static void main(String[]args){
Gps app = new Gps();
app.enterEventDispatcher();
}

public String locString;
public double lon;
public double lat;
public String extraInfo;
private Gps()
{
GpsScreen gf = new GpsScreen(this);
pushScreen(gf);

}

public class GpsScreen extends MainScreen{
// public GpsScreen(){
//
// }

public GpsScreen(Gps aThis) {
//SetTitle("LocationProvider");
LabelField lf = new LabelField("Select 'LocationView' from the menu.");// The MapView object is set to Zoom Level 3. Location is Ottawa, ON, Canada at Latitude 45.42349, Longitude -75.69792");
add(lf);
addMenuItem(mapLocation);
}
private MenuItem mapLocation = new MenuItem("LocationView" , 100, 10){
public void run(){
Spot spot = new Spot(_mv);
UiApplication _app = UiApplication.getUiApplication();
_app.pushScreen(spot);
}
};
// private void SetTitle(String string) {
// throw new UnsupportedOperationException("Not yet implemented");
//}
}
public double getLatitude(){
return lat;
}
//
public double getLongitude(){
return lon;
}

}


/*Spot.java*/


package com.rim.track;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.location.Coordinates;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationProvider;
import net.rim.blackberry.api.invoke.Invoke;
import net.rim.blackberry.api.invoke.MapsArguments;
import net.rim.blackberry.api.maps.MapView;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.FontFamily;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;


public class Spot extends MainScreen {//implements DrawStyle{


private Font headerFont = SmallFont();
MapView view ;

private int fieldWidth;
private int fieldHeight;
private Timer headerTimer;// = new Timer();
private TimerTask headerTask;
// public String locString = "Initialising GPS...";
//public String extraInfo = "-";
public double lat;
public double lon;
SpotThread r;
//
private Spot(Gps obj) {
super(Field.NON_FOCUSABLE);
r = new SpotThread(obj);

fieldHeight = 12;
fieldWidth = Graphics.getScreenWidth();

//
headerTask = new TimerTask() {
public void run() {
//invalidate();
r.start();
}
};
headerTimer.scheduleAtFixedRate(headerTask, 60000, 60000);
}

Spot(MapView _mv) {
view = _mv;
}

public double getLatitude(){
return lat;
}
//
public double getLongitude(){
return lon;
}

public void LaunchMaps(){
String latString = "" + lat;
latString = latString.substring(0, latString.indexOf(".")) + latString.substring(latString.indexOf(".")+1, latString.length());

String lonString = "" + lon;
lonString = lonString.substring(0, lonString.indexOf(".")) + lonString.substring(lonString.indexOf(".")+1, lonString.length());

view.setLatitude(Integer.parseInt(latString));
view.setLongitude(Integer.parseInt(lonString));
view.setZoom(1);
//synchronized(UiApplication.getEventLock()){
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(view));
// }
}
//
// protected void layout(int width, int height) {
// setExtent(getPreferredWidth(), getPreferredHeight());
// }
//
public int getPreferredWidth() {
return fieldWidth;
}
//
public int getPreferredHeight() {
return fieldHeight;
}
//
protected void paint(Graphics graphics) {
graphics.setColor(0xDDDDDD);
graphics.drawLine(0,0,fieldWidth, 0);
graphics.drawLine(0, fieldHeight-1, fieldWidth, fieldHeight-1);
graphics.setFont(headerFont);
graphics.setColor(0x666666);
// graphics.drawText(locString, 1,1);
}
//
public static Font SmallFont(){
try {
FontFamily theFam = FontFamily.forName("SYSTEM");
return theFam.getFont(net.rim.device.api.ui.Font.PLAIN, 10);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
}
class SpotThread extends Thread {
private Timer locationTimer = new Timer();
private TimerTask locationTask;
String gpsString;
// String extraInfo;
double lat;
double lon;
Location l;
Coordinates c;
Criteria cr= new Criteria();
LocationProvider lp;
Gps _locationField;

// SpotThread(Gps obj) {
// throw new UnsupportedOperationException("Not yet implemented");
// }

//
public SpotThread(Gps locationField) {
_locationField = locationField;
}


//
public void run() {
try {
lp = LocationProvider.getInstance(cr);
} catch (LocationException ex) {
gpsString = ex.toString();
//extraInfo = "-";
if(gpsString.indexOf("LocationException:") > 0){
gpsString = gpsString.substring(gpsString.indexOf("LocationExc eption:"), gpsString.length());
}
ex.printStackTrace();
}

try {
checkLocation();
// _locationField.locString = gpsString;
_locationField.lon = lon;
_locationField.lat = lat;
// _locationField.extraInfo = extraInfo;
} catch (Exception ex) {
ex.printStackTrace();
}

}

public void checkLocation(){
try {
cr.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
l = lp.getLocation(35);
c = l.getQualifiedCoordinates();
if(c != null ) {
lat = c.getLatitude();
lon = c.getLongitude();
gpsString = "Latitude : " + lat + " Longitude : " + lon;
//extraInfo = l.getExtraInfo("application/X-jsr179-location-nmea");
//System.out.println("extrainfo: " + extraInfo);
} else {
gpsString ="Location API failed";
}
} catch (LocationException ex) {
gpsString = ex.toString();
//extraInfo = "-";
if(gpsString.indexOf("LocationException:") > 0){
gpsString = gpsString.substring(gpsString.indexOf("LocationExc eption:"), gpsString.length());
}
ex.printStackTrace();
} catch (InterruptedException ex) {
//extraInfo = "-";
gpsString = ex.toString();
ex.printStackTrace();
}
}
}
Offline  
Old 09-30-2008, 10:23 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Oct 2007
Location: Los Angeles
Model: None
PIN: N/A
Carrier: ATT
Posts: 1,638
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

This might be better topic for the Developer forum.
Offline  




Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.