01-06-2010, 07:05 AM
|
#1 (permalink)
|
| New Member
Join Date: Dec 2009 Model: 8300 PIN: N/A Carrier: email
Posts: 1
Post Thanks: 0 Thanked 0 Times in 0 Posts
| Getting the current location using GPS in BlackBerry Please Login to Remove! 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 |
| Offline
| |