如何知道没有'onLocationChange“法GPS定位onLocationChange、GPS

2023-09-08 09:18:47 作者:枭雄戏美人

我想在点击一个按钮,并在我想要发送位置信息短信发送短信。我想:

I want to send an SMS on click of one button and in the SMS i want to send location information. i tried:

 location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

但它第一次显示了空,因为没有已知的发现地点。 因此,我要等火'onLocationChange的LocationListener的,但我不希望出现这种情况。

but for the first time it shows null because no known location found. Hence i have to wait to fire 'onLocationChange' of the LocationListener, but i dont want that.

请告诉我一些其他的方式,这样我可以在一杆获得位置。 谢谢。

Please tell me some other way so that i can get location at one shot. thanks.

推荐答案

获取GPS坐标在第一时间(如GPS服务没有运行),可以是一个耗时的过程,因为GPS需要做大量的初始化。第一onLocationChange的发射是Android的GPS说的道:我知道我现在在哪里所以,你可能必须想出一个办法与onLocationChange工作。

Acquiring GPS coordinates the first time (if GPS Service is not running) can be a time-intensive process because the GPS needs to do a lot initializing. The firing of the first onLocationChange is a way of Android's GPS to say: "I know where I am now." So you might have to figure out a way to work with onLocationChange.

的方式为您使用您的短信/ GPS API的需求是全球定位系统的不断运行。你有没有看着/试过了吗?你也可以等待您的短信过程,直到GPS位置可用,直到有合理的长度超时事件发生,然后发送短信。而后续的请求应该更迅速,因为你有你的GPS初始化去。在任何情况下,你不能在纬度/经度实时计算从GPS服务。

The way to you use your SMS/GPS API as on demand is to the GPS service is running constantly. Have you looked into/tried that? You could also wait in your SMS process until a GPS location is available, until some reasonable-length timeout event occurs, and then send the SMS. And subsequent requests should go much more quickly since you have your GPS initialized. In any case, you cannot count on the lat/long from the GPS Service in real time.

下面是上移动GPS 。这是一般的,但读通过它揭示原因,你不能简单地得到一个GPS读取在触摸一个按钮。

Here's a great article on mobile GPS. It's general but reading through it will reveal the reasons why you cannot simply get a GPS reading "at the touch of a button."