GPS定位信息问题
在我的应用程序中,需要获取当前位置信息,我使用以下代码;并将其称为“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你在模拟器中模拟过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.
第一步是将一些日志记录放入异常处理程序中。
这可能会向您显示正在抛出一些异常。一旦弄清楚了这一点,您就可以看到代码可能是如何做错事而导致异常的。
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.
这可能不是 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.
有关此“混乱”的解释,请参阅:黑莓基于位置的服务
for an explanation to this "Mess" please see : blackberry location-based services