Mobile Phone Positioning for Android Development

Source: Internet
Author: User

Mobile Phone Positioning for Android Development

Mobile Phone Positioning is based on three methods: 1. Network Positioning; 2. base station positioning; 3. GPS Positioning

1. Network Positioning

The premise is that the network must be connected: Wifi, 3G, 2G

Obtained IP Address
For example, QQ of Rainbow edition and QQ of coral insects edition have a function to display the IP address of the other party;
Display the specific location based on the IP address;

The principle is to set up the IP address of a database to correspond to that location; this feature is used in early police cases;

Limitations: For fixed IP addresses.
If the mobile phone network or IP address is dynamically distributed, this deviation is very large. This situation cannot meet the requirements.

2 base station positioning

Working principle: a base station is needed for phone calls. Mobile Phone Positioning also uses base stations.
The mobile phone can be located after receiving signals from three base stations.
The positioning of base stations may be very accurate, for example, where there are many base stations;
If the number of base stations is small, the difference will be very large.
Precision: dozens of meters to several kilometers;

3 GPS Positioning

A-GPS uses the satellite positioning requires networked Auxiliary Correction location (mobile phone often used, priority request network, get the information cache of the previously stored satellite orbit ,)
Features: Search for satellites, and the head must be empty;

Impact conditions: clouds, buildings, and trees.

The following is the implementation code:

Package com. andy. gpsdemo; import com. example. gpsdemo. r; import android. support. v7.app. actionBarActivity; import android. widget. textView; import android. location. criteria; import android. location. location; import android. location. locationListener; import android. location. locationManager; import android. OS. bundle; public class MainActivity extends ActionBarActivity {// location service private LocationManager locationManager; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); locationManager = (LocationManager) getSystemService (LOCATION_SERVICE);/* List
 
  
Provider = locationManager. getAllProviders (); for (String string: provider) {System. out. println (string);} * // register the listening location service // set the condition Criteria criteria = new Criteria () for the location provider; criteria. setAccuracy (Criteria. ACCURACY_FINE); // obtain the exact location // criteria. setAccuracy (Criteria. ACCURACY_FINE); // sets it to the maximum precision. // criteria. setAltitudeRequired (false); // The elevation information is not required. // criteria. setBearingRequired (false); // The orientation information is not required. // criteria. setCostAllowed (true); // whether to allow payment // criteria. setPowerRequirement (Criteria. POWER_LOW); // power requirement String proveder = locationManager. getBestProvider (criteria, true); locationManager. requestLocationUpdates (proveder, 0, 0, new LocationListener () {@ Overridepublic void onLocationChanged (Location location) {// callback String longpolling = "longitude:" + location. getlongpolling (); String latitudeString = "dimension:" + location. getLatitude (); String accuracy = "precision:" + location. getAccuracy (); TextView textView = new TextView (MainActivity. this); textView. setText (longmargin + "\ n" + latitudeString + "\ n" + accuracy); setContentView (textView) ;}@ Overridepublic void onProviderDisabled (String provider) {// when a location provider cannot use} @ Overridepublic void onProviderEnabled (String provider) {// when a location provider can use} @ Overridepublic void onStatusChanged (String provider, int status, bundle extras) {// when the status changes, the callback is enabled-disabled; Disabled-enabled }});}}
 

The layout file is:

     
  
 


The required permissions are:

// Test and use the simulator


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.