How to find GPS location without onLocationChange method

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

location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 

but for the first time it shows zero because an unknown location is found. So I have to wait to start onLocationChange from the LocationListener, but I do not want this.

Please tell me another way so that I can find a place in one picture. thanks.

+4
source share
1 answer

Getting GPS coordinates for the first time (if the GPS service isn’t working) can be a time-consuming process because GPS needs to be initialized a lot. Dismissing the first onLocationChange is an Android GPS way of saying, "I know where I am now." Therefore, you may have to figure out a way to work with onLocationChange.

The way you use your SMS / GPS API on demand is to keep the GPS service running . Have you studied / tried this? You can also wait for your SMS process until the GPS location is available, until there is a certain amount of time to wait for a timeout of a reasonable length, and then send an SMS message. And subsequent queries should go much faster since you initialized your GPS. In any case, you cannot count on lat / long from the GPS service in real time.

Here is a great article on mobile GPS . This is common, but reading through it will show the reasons why you cannot just get GPS readings β€œat the click of a button."

0
source

Source: https://habr.com/ru/post/1342824/


All Articles