-1

在我的应用程序中,需要取当前的位置信息,我使用下面的代码;并称之为buttonclick,但它不能在设备和模拟器中工作,如果任何人有任何想法请帮助。GPS位置信息问题

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

你有它不工作更多的细节?例如,你是否遇到异常?如果是这样,在哪一行?或者你的结果与预期不同?需要一些关于什么不工作的更多细节。 – 2011-02-08 16:59:04

回答

0

你在模拟器中模拟了GPS吗?模拟 - > GPS位置,然后在对话框中添加一个位置或配置一条模拟路线。

0

第一步是在异常处理程序中添加一些日志记录。

这可能会告诉你一些异常被抛出。一旦你明白了,你可以看到代码是如何做错的,导致异常。

0

这可能不是GPS问题。很可能您尝试更新UI字段而不在事件线程中。有关如何避免这种情况的信息,请参阅my answer to this related question

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

一个解释这个“烂摊子”,请参阅:blackberry location-based services

+0

没有解释去与这混乱? – 2012-10-06 01:56:08