Today, due to work needs, I took out a GPS test program I wrote before and revised it. This program has a history. I wrote it in 2011, not long after I learned Android development. It was an experimental work. Now it is needed for work, so I took it out and revised it. At the same time, I found that I don’t know much about Android’s GPS service, so today I specially read some materials about GPS service and recorded the relevant knowledge points. I have been working on GPS-related embedded software for several years, so when it comes to making a program to test the GPS positioning module, my first reaction is to read the data of the GPS module through the serial port, and then parse the GPS NMEA format data. NMEA is a standardized data format that is not only used in GPS, but also in some other industrial communications. Parsing the relevant data and then displaying it completes a basic GPS positioning test function. After some research, I found that there is no need to read NMEA data for GPS-related positioning services on Android. Android has already packaged the relevant services, and all you have to do is call the API. I don't know whether I should feel happy or confused about this. (Android also provides an interface for reading NMEA, which will be discussed below) 1. Android Location Services Let's first look at the support provided by Android for location services: Android location services are all located under location, and there are relevant instructions above, so I won't analyze them in detail here. One thing I need to say is that GpsStatus.NmeaListener officially says that it can read NMEA data, but I tested it and found that it did not read NMEA data. I checked some information and it said that Google did not implement the data feedback function at the bottom layer. I need to check the source code when I have time. 2. LocationManager positioning
3. GpsStatus Listener The above gives the initialization steps of the positioning service, but we all know that GPS satellites broadcast data regularly, which means that we will receive GPS data from satellites regularly. We cannot actively request data from satellites, but can only receive data passively. (China's Beidou 2 can send satellite messages to satellites) Therefore, we need to register a listener to process the data returned by the satellite.
4. Get the searched satellites
The above is to get the number of satellites searched from the status value, mainly through status.getSatellites(). The obtained GpsSatellite object is saved in a queue for later interface refresh. The above is to get the GPS status listener. In addition to the GPS status, we also need to listen to a service, namely: LocationListener, positioning listener, to listen to the change of location. This is very important for applications that provide positioning services. 5. LocationListener
The location monitoring callback is used to automatically call back when the GPS location changes. We can get the current GPS data from here. In addition, we can get the GPS location information, including longitude and latitude, speed, altitude, etc., through the location parameter provided by the callback function. 6. Get location information (longitude and latitude, number of satellites, altitude, positioning status)
7. Get the specified satellite information (direction angle, altitude angle, signal-to-noise ratio)
Using the direction angle and altitude angle, we can draw a two-dimensional graph to show the position of the satellite on the earth where the signal-to-noise ratio has a greater effect. General satellite positioning test software provides a state diagram of the signal-to-noise ratio, which represents the GPS module's satellite search capability. 8. Draw a 2D satellite position map Here is the effect of the GPS test I did: Below is a method for calculating the position of a satellite in a two-dimensional image based on the direction angle and altitude angle. The green dot on the left side of the above rendering represents the satellite position. The signal-to-noise ratio bar graph on the right represents the satellite's ability to receive signals.
The drawing of signal-to-noise ratio is just a unit conversion, so I won’t give the code here. 9. Summary: Android provides us with very convenient location services, mainly through the GpsStatus, LocationManager, GpsSatellite these classes to implement related services and monitoring. However, I personally think it would be very convenient to be able to directly read NMEA data, at least for some applications, more information can be obtained. |
<<: Four scenarios that are best suited for RxJava
>>: Designing an APP from scratch: Android design specifications
Friends who have used this kind of water dispense...
Why can a teacher who teaches criminal law attrac...
In Chongqing, winter is the peak season for eatin...
Gaming experience has always been an important us...
At present, there are relatively good solutions f...
The Chinese names of plants are like refined code...
In both speeches, solutions to three pain points ...
Zhang Shanling's 21 Lectures on Alibaba's...
Recently I have been thinking about where the pat...
[[201617]] According to AppleInsider on August 29...
1. Daily P-picture splash ads Displayed to users ...
Do you often worry about having an introverted ch...
The domestic mobile game industry has become a re...
Introduction: Mysterious backs, silent assassinat...
Zang Qichao's equity incentive and mechanism ...