BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   Getting the current location using GPS in BlackBerry (http://www.blackberryforums.com/developer-forum/215820-getting-current-location-using-gps-blackberry.html)

sanjay kumar 01-06-2010 07:05 AM

Getting the current location using GPS in BlackBerry
 
Hi ,

I want to create a black berry application which will display the current location latitude and longitude when the location changes. So how can I test it inside black berry simulator 9530.

The code is mentioned below , Can any one help me ? Does the code is correct ?

package blackberry;

import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;

import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class GPSInformation extends MainScreen{

private LocationProvider locationProvider = null ;

private int _interval = -1 ;
private int _timeout = 1 ;
private int _maxAge = 1 ;

private double _longitude = 1 ;
private double _latitude = 2 ;

public GPSInformation() {

try {
locationProvider = LocationProvider.getInstance(null);

if(locationProvider != null) {
locationProvider.setLocationListener(new LocationListenerImp(), _interval, _timeout, _maxAge);
}
}
catch (Exception e) {

}
}

private class LocationListenerImp implements LocationListener {

public void locationUpdated(LocationProvider provider, Location location) {

if(location.isValid()) {
_longitude = location.getQualifiedCoordinates().getLongitude();
_latitude = location.getQualifiedCoordinates().getLatitude();
}

add(new LabelField("Longitude : " +_longitude));
add(new LabelField("Latitude : " +_latitude));
}

public void providerStateChanged(LocationProvider provider, int newState) {
// TODO Auto-generated method stub
}
}
}

Thanks

hrbuckley 01-06-2010 08:15 AM

Simulators for Blackberries equipped with GPSs are able to simulate GPS data.

You may want to move this topic to the developers' forum, and check out the thread there on how to post source code.

Dougsg38p 01-06-2010 09:39 AM

When you start the simulator, select "Simulate / GPS Location" from the simulator menu.


All times are GMT -5. The time now is 01:12 PM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.