-1

私のアプリケーションでは、現在の位置情報を取得する必要があります。次のコードを使用します。それをボタンクリックと呼びますが、デバイスとシミュレーターでは機能しません。何かアイデアがあれば助けてください。

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

4 に答える 4

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

この「混乱」の説明については、次を参照してください:ブラックベリーの位置情報サービス

于 2012-10-05T07:07:54.753 に答える
0

ステップ 1 は、例外ハンドラにログを記録することです。

これはおそらく、何らかの例外がスローされていることを示しています。それを理解したら、コードが例外を引き起こす何か間違ったことをしている可能性があることを確認できます。

于 2011-02-08T17:13:23.143 に答える
0

これはおそらく GPS の問題ではありません。イベント スレッドに参加せずに UI フィールドを更新しようとしている可能性があります。それを回避する方法については、この関連する質問に対する私の回答を参照してください。

于 2011-02-08T18:38:35.340 に答える
0

シミュレーターで GPS をシミュレートしましたか? [シミュレート] -> [GPS 位置] ダイアログで位置を追加するか、シミュレートされたルートを構成します。

于 2011-02-08T16:49:35.770 に答える