Android GPS application design

Source: Internet
Author: User

Introduction to GPS

GPS is short for the English Global Positioning System (GPS. GPS was jointly developed by the US Army of land, sea, and air in 1970s.

A new generation of spatial satellite navigation and positioning systems. Its main purpose is to provide real-time, around-the-clock, and global navigation services for the land, sea, and air fields.

For military purposes such as intelligence collection, nuclear explosion monitoring, and emergency communications, after more than 20 years of research and experiments, it costs US $30 billion to cover the world by March 1994.

Up to 98% of the 24 GPS satellite constellations have been deployed.


GPS Positioning Principle

The basic principle of GPS positioning is to determine the data to be tested based on the instantaneous position of the High-speed satellite as the known starting data, using the method of spatial distance Rear Intersection.

Point position ., Assuming that the GPS receiver is placed on the ground to be tested at t time, the time when the GPS signal arrives at the receiver can be determined.

The following four equations can be determined based on the satellite calendars received by the receiver)

Signature + signature/Signature + zvHA4LXE1/fTw8/Signature/s7xoaI8L3A + CjxwPrbUz/Signature/zsvrJ + signature + tcSz6c/Signature/bjDttTP87/Signature + m8/rXEz + Signature expires + nP88DgoaM8L3A + expires/zDx8C0u/expires + expires/HIobaozrvQxc + expires/expires + PGJyPgo8L3A + expires + tglzddxtdhjhs + region + 3da4tqjM9bz + u/HIocL61 + region/M8L3A + region + 69/examples + samples + s/samples/L6vuOY8L3A + samples/samples + samples/HIobaozrvQxc + iLLKizai5/samples + samples/HIobaozrvQxc + iLLKizai5/samples + PC9wPgo8cD48YnI + signature/M8L3A + signature/Signature + dW + signature + MLnyv2 + 3TwvcD4KPHA + signature/Signature + signature + signature/Signature + signature + PGJyPgo8L3A + signature C9zdHJvbmc + signature/HIobaozrvQxc + itcS3vc/Signature + signature + Signature + signature/Signature + signature/HT0Le9z/LQxc + signature + PGJyPgo8L3A + signature + u/HIobaozrvQxc + iPC9zdHJvbmc + signature/Signature + x7cq + signature/Signature + signature + Signature + x7cq + signature + 7PGu/Signature + signature + 3 Records/Signature + signature/cLLobHM9bz + o6zL/Signature vcd4kpha + signature/Signature/HIobaozrvQxc + signature + signature + signature + PGJyPgo8L3A + signature + PGJyPgo8L3A + CjxwPsf3vfy + signature/Signature + u4w7XjtcS + signature + 1zbO/Signature + signature/Signature + oaM8L3A + signature + NPysOu + release/release + m8/release + release/release + Mjryei2qMf40/LKsczh0NHTw7unoaM8L3A + release/dfTtPrC6zo8L3A + release + u/release + release = "brush: java; "> // get the LocationManager object mLocationManager = (LocationManager) getSystemService (Context. LOCATION_SERVICE); // obtain the name List of all locationproviders ProviderNames = mLocationManager. getAllProviders ();Get the specified LocationProvider by name

// Obtain the GPS-based LocationProviderLocationProvider locProvider = lm. getProvider (LocatinManager. GPS_PROVIDER)
Obtain LocationProvider based on Criteria
MProviders = (ListView) findViewById (R. id. providers); // obtain the system's LocationManager object mLocationManager = (LocationManager) getSystemService (Context. LOCATION_SERVICE); // create the filter condition Criteria cri = new Criteria () for a LocationProvider; // The setting requires that the LocationProvider be free of charge. Cri. setCostAllowed (false); // The setting requires that the LocationProvider provide the height information cri. setAltitudeRequired (true); // The LocationProvider is required to provide the direction information cri. setBearingRequired (true); // obtain the name List of all qualified locationproviders in the system.
 
  
ProviderNames = mLocationManager. getProviders (cri, true );
 


Obtain positioning data:

// Create the LocationManager object mLocationManager = (LocationManager) getSystemService (Context. LOCATION_SERVICE); // obtain the latest Location information from GPS. location Location = mLocationManager. getLastKnownLocation (LocationManager. GPS_PROVIDER); // use location to display updateView (location) based on EditText; // you can obtain the location information mLocationManager of GPS every 2 seconds. requestLocationUpdates (LocationManager. GPS_PROVIDER, 2000, 8, new LocationListener () {@ Override public Void onLocationChanged (Location location) {// when the GPS location information changes, update the Location updateView (location) ;}@ Override public void onProviderDisabled (String provider) {updateView (null) ;}@ Override public void onProviderEnabled (String provider) {// update the location updateView (mLocationManager) when the GPS LocationProvider is available. getLastKnownLocation (provider);} @ Override public void onStatusChanged (String provider, int status, Bundle Extras) {}});} // update the public void updateView (Location newLocation) {if (newLocation! = Null) {StringBuilder sb = new StringBuilder (); sb. append ("real-time location information: \ n"); sb. append ("longitude:"); sb. append (newLocation. getlongpolling (); sb. append ("\ n latitude:"); sb. append (newLocation. getLatitude (); sb. append ("\ n Height:"); sb. append (newLocation. getAltitude (); sb. append ("\ n speed:"); sb. append (newLocation. getSpeed (); sb. append ("\ n Direction:"); sb. append (newLocation. getBearing (); mEditText. setText (sb. toString ();} else {// If the input Location object is null, The EditText mEditText will be cleared. setText ("");}

 
 
This program requires the permission to access the GPS signal, so you need to add the authorization information in the AndroidManifest. xml file.

Obtains the Location information from the Location, including the user's longitude, latitude, height, direction, and moving speed.

Listener, which requests location information to the LocationProvider every three seconds. When the LocationProvider is available, it is unavailable or

When the bit information changes, the system calls back the corresponding method update interface.

If the program is combined with Google Map, and the program displays the user's location on the Map in real time based on the information provided by GPS, the GPS navigation system can be developed.


Approaching warning:

// Locate the service manager object LocationManager locationManager; // obtain the LocationManager object locationManager = (LocationManager) getSystemService (Context. LOCATION_SERVICE); // defines the approximate longitude and latitude of building 4 of Wanli University, double longpolling = 123.427109; double latitude = 41.764998; // defines the radius (2000 meters) float radius = 2000; // define Intent intent = new Intent (this, ProximityAlertReciever. class); // wrap Intent into PendingIntent pendingIntent = PendingIntent. getBroadcast (this, 1, intent, 0); // Add nearby warning locationManager. addProximityAlert (latitude, longpolling, radius,-1, pendingIntent );
Corresponding BroadcastReceiver:
Public class ProximityAlertReciever extends BroadcastReceiver {@ Override public void onReceive (Context context, Intent intent) {// obtain whether to enter the specified region boolean isEnter = intent. getBooleanExtra (LocationManager. KEY_PROXIMITY_ENTERING, false); if (isEnter) {// display the prompt Toast. makeText (context, "you are close to building 4 of Wanli College", Toast. LENGTH_LONG ). show ();} else {// display the prompt Toast. makeText (context, "you have left building 4 of Wanli College", Toast. LENGTH_LONG ). show ();}}}
     
     
     
 


Calculate the two-point distance:

Final float [] results = new float [3]; Location. distanceBetween (20.123, 30.05644, 30.124, 40.543, results); final float bearing = results [1]; mEditText. setText (String. valueOf (results [0]) + "meter ");





Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.