GPS定位信息问题

发布于 2024-10-16 10:23:00 字数 1843 浏览 9 评论 0原文

在我的应用程序中,需要获取当前位置信息,我使用以下代码;并将其称为“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();
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

征棹 2024-10-23 10:23:00

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

Have you simulated a GPS in the simulator? Simulate -> GPS Position then in the dialog add a position or configure a simulated route.

梦旅人picnic 2024-10-23 10:23:00

第一步是将一些日志记录放入异常处理程序中。

这可能会向您显示正在抛出一些异常。一旦弄清楚了这一点,您就可以看到代码可能是如何做错事而导致异常的。

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.

嗼ふ静 2024-10-23 10:23:00

这可能不是 GPS 问题。您可能正在尝试在不处于事件线程的情况下更新 UI 字段。有关如何避免这种情况的信息,请参阅我对此相关问题的回答

This is probably not a GPS problem. It's likely that you're trying to update a UI field without being on the event thread. See my answer to this related question for information on how to avoid that.

孤城病女 2024-10-23 10:23:00
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());
}

有关此“混乱”的解释,请参阅:黑莓基于位置的服务

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

for an explanation to this "Mess" please see : blackberry location-based services

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文