开发者

How to know GPS Location without 'onLocationChange' method

开发者 https://www.devze.com 2023-02-15 18:00 出处:网络
I want to send an SMS on click of one button and in the SMS i want to send location information. i tried:

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

 locati开发者_JAVA技巧on = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

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.


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.

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.

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."

0

精彩评论

暂无评论...
验证码 换一张
取 消