-1

In my application,there is a need of take current location information, I use the follwing code; and call it buttonclick,But it doesn't work in the device and in the simulator,if any one have any idea please help.

private void getLocationServices(){
    Thread geoThread=new Thread(){  
        public void run(){
            try{
                Criteria myCriteria = new Criteria();
                myCriteria.setCostAllowed(false);
                try{
                    LocationProvider myLocationProvider = LocationProvider.getInstance(myCriteria);
                    try{
                        locationaddress=new AddressInfo();
                        Location myLocation = myLocationProvider.getLocation(300);
                        _lattitude = myLocation.getQualifiedCoordinates().getLatitude();
                        _longitude = myLocation.getQualifiedCoordinates().getLongitude();
                        int intLatitude = (int) _lattitude * 100000;
                        int intLongitude = (int) _longitude * 100000;
                        try{
                            Landmark[] results= Locator.reverseGeocode(intLatitude, intLongitude, Locator.ADDRESS);
                            if (results != null && results.length > 0) {
                                locationaddress=results[0].getAddressInfo();
                                lblLoc.setText(locationaddress.getField(AddressInfo.CITY));
                            }
                        }catch (Exception e) {
                            // TODO: handle exception
                        }

                    }catch (Exception e) {
                        // TODO: handle exception
                    }

                }catch (Exception e) {
                    // TODO: handle exception
                }
            }catch (Exception e) {
                // TODO: handle exception
            }
        }
    };
    geoThread.start();
}
rfsk2010
  • 8,271
  • 4
  • 28
  • 43
Jisson
  • 2,915
  • 7
  • 34
  • 67
  • Do you have more details on where it is not working? For example, are you getting an exception? If so, on what line? Or are you results different than expected? Need some more details on what is not working. – Scott W Feb 08 '11 at 16:59

4 Answers4

0
CustomMapField mMapField;
Coordinates mCoordinates;
BlackBerryCriteria blackBerryCriteria = null;
BlackBerryLocation blackBerryLocation = null;
BlackBerryLocationProvider blackBerryLocationProvider = null;
double Doublelat = 0.0;
double Doublelng = 0.0;
blackBerryCriteria = new BlackBerryCriteria();
if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CELLSITE)){
   blackBerryCriteria.setMode(GPSInfo.GPS_MODE_CELLSITE);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST)){
   blackBerryCriteria.setMode(GPSInfo.GPS_MODE_ASSIST);
}else if(GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)){
   blackBerryCriteria.setMode(GPSInfo.GPS_MODE_AUTONOMOUS);
}else{
   blackBerryCriteria.setCostAllowed(true);
   blackBerryCriteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
} try {
   blackBerryLocationProvider = (BlackBerryLocationProvider)               BlackBerryLocationProvider.getInstance(blackBerryCriteria);
   blackBerryLocation = (BlackBerryLocation) blackBerryLocationProvider.getLocation(60);
   QualifiedCoordinates qualifiedCoordinates = blackBerryLocation.getQualifiedCoordinates();
   Doublelat = qualifiedCoordinates.getLatitude();
   Doublelng = qualifiedCoordinates.getLongitude();
   mCoordinates = new  Coordinates(Doublelat, Doublelng, 0);
   MapView mapView = new MapView();
   mapView.setLatitude(finalintlat);
   mapView.setLongitude(finalintlng);
   mapView.setZoom(10);
   MapsArguments mapsArgs = new MapsArguments(mapView);
   Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, mapsArgs);
}catch(Exception e){
   System.out.println("Error in location :"+e.toString());
   System.out.println("Error in location :"+e.getMessage());
}

for an explanation to this "Mess" please see : blackberry location-based services

Community
  • 1
  • 1
Nequita
  • 89
  • 7
0

Have you simulated a GPS in the simulator? Simulate -> GPS Position then in the dialog add a position or configure a simulated route.

Richard
  • 8,950
  • 2
  • 16
  • 24
0

Step one is to put some logging in your exception handlers.

This will probably show you some exception is being thrown. Once you have that figured out, you can see how the code might be doing something wrong that causes the exception.

Michael Donohue
  • 11,606
  • 5
  • 29
  • 44
0

This is probably not a GPS problem. It's likely that you're trying to update a UI field without being on the event thread. See my answer to this related question for information on how to avoid that.

Community
  • 1
  • 1
Eric Giguere
  • 3,435
  • 13
  • 11