BlackBerry Forums Support Community

Closed Thread
LinkBack Thread Tools
Old 01-06-2010, 08:05 AM   #1 (permalink)
New Member
Join Date: Dec 2009
Model: 8300
Carrier: email
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

Old 01-06-2010, 09:15 AM   #2 (permalink)
BlackBerry Extraordinaire
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts

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.
My other Blackberry is a PlayBook.
Old 01-06-2010, 10:39 AM   #3 (permalink)
BlackBerry Extraordinaire
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

1pc sansung SAMSUNG FARA N-70a CPL9631
1pc sansung SAMSUNG FARA N-70a CPL9631 pictureSamsung DC64-00802A Diaphragm/Sealing Rubber Door
Samsung DC64-00802A Diaphragm/Sealing Rubber Door picture1pc sansung PLC CPL9502
1pc sansung PLC CPL9502 picture1pc sansung SAMSUNG FARA N-70a CPL93023
1pc sansung SAMSUNG FARA N-70a CPL93023 picture1pc SAMSUNG sansung MACP-PWXA
1pc SAMSUNG sansung MACP-PWXA picture

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