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();
}
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.