无法在黑莓中检索正确的位置

时间:2011-11-06 12:51:50

标签: blackberry java-me geolocation

这是我写的代码来检索纬度,经度,但它不起作用;它显示一个标题集的空白屏幕:

public class MyScreen extends MainScreen
{
/**
 * Creates a new MyScreen object
 */
public MyScreen()
{     

    super(MainScreen.NO_VERTICAL_SCROLL);
    // Set the displayed title of the screen
    try{
    //Disabling vertical scrolling for mainscreen
    // setting the title
    Dialog.alert("before init");
    initialize();
    //creating a bit map resource from the image.
    }catch(Exception e){
        e.printStackTrace();
    }
}
public void initialize()
{ 
   try{
       //(new LocationThread()).start();
       Dialog.alert("In init");
       Criteria criteria = new Criteria();
        criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setCostAllowed(true);
        criteria.setPreferredPowerConsumption(Criteria.POWER_USAGE_LOW);
        Dialog.alert("criteria");
        BlackBerryCriteria bc=new BlackBerryCriteria(GPSInfo. GPS_MODE_NONE );          
         try {
                LocationProvider lp=LocationProvider.getInstance(criteria);
                Dialog.alert("Before if");
                if(lp !=null)
                {
                    Location loc=lp.getLocation(-1);
                    if(loc != null){
                    QualifiedCoordinates qc=loc.getQualifiedCoordinates();
                    double lat=qc.getLatitude();
                    double lon=qc.getLongitude();
                    Dialog.alert(String.valueOf(lat));
                    Dialog.alert(String.valueOf(lon));
                    }
                }
        } catch (LocationException e) {
            // TODO Auto-generated catch block
            Dialog.alert("LOcation Exception");
        } catch (NullPointerException e) {
            // TODO Auto-generated catch block
            Dialog.alert("Null Pointer Exception");

        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            Dialog.alert("Interrupted Exception");

        }
   }catch(NullPointerException e){
        Dialog.alert("NullPointer Exception");
   }

}
}

1 个答案:

答案 0 :(得分:0)

您的Criteria规范要求Cellsite作为地理定位模式。您确定您的提供商是否支持此设备并且您的设备是否已正确配置?