在我的应用程序中,需要获取当前位置信息,我使用以下代码;并称之为buttonclick,但它在设备和模拟器中不起作用,如果有人有任何想法请帮忙。
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();
}