Mobile positioning is based on the following three ways: 1. Network positioning; 2. Base station positioning; 3. GPS positioning
1 Network positioning
The premise is that you must connect to the network: WiFi, 3G, 2G
Get to IP Address
For example: Rainbow version of QQ, polyp version of QQ, there is a function to display each other's IP;
Display the specific location according to IP;
The principle is to set up a library that IP address corresponds to that place; the early police solved the case by using this characteristic;
Limitations: For fixed IP addresses.
If the mobile network or IP address is dynamically distributed IP, this deviation is very large. This situation is not enough to meet the demand.
2 Base Station positioning
Working principle: Mobile phone can call, it is necessary base station. Cell phone positioning is also used base station.
You can get a signal from 3 base stations near your mobile phone, and you'll be able to locate it.
Base station location may be very accurate, such as the base station more places;
If the base station is small, it will vary greatly.
Accuracy: Dozens of meters to a few kilometres;
3 GPS Positioning
A-gps use of satellite positioning requires a network of auxiliary correction locations (mobile phones are often used, priority request network, access to the previously saved satellite track information cache)
Features: Need to search for satellites, the head must be empty;
Impact conditions: Clouds, buildings, trees.
Here's the code for the implementation:
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<string> Provider = Locationmanager.getallproviders (); for (string string:provider) {System.out.println (string);} *///Register Monitoring Location Service//Set conditions for location provider criteria = new criteria (); criteria.setaccuracy (criteria.accuracy_fine);//Get precise position/ /Criteria.setaccuracy (criteria.accuracy_fine);//set to maximum precision//criteria.setaltituderequired (FALSE);//Altitude information not required// Criteria.setbearingrequired (false);//Do notAsk for azimuth information//criteria.setcostallowed (TRUE),//whether to allow pay//Criteria.setpowerrequirement (Criteria.power_low),//Requirements for power string Proveder = Locationmanager.getbestprovider (criteria, true); Locationmanager.requestlocationupdates (proveder, 0, 0, New Locationlistener () {@Overridepublic void onlocationchanged (location site) {//callback string longitude = "Longitude:" + L when changing position) Ocation.getlongitude (); String latitudestring = "Dimension:" + location.getlatitude (); String accuracy = "accuracy:" + location.getaccuracy (); TextView TextView = new TextView (mainactivity.this), Textview.settext (longitude + "\ n" + latitudestring+ "\ n" + accuracy); Setcontentview (TextView);} @Overridepublic void onproviderdisabled (String provider) {//When a location provider is not allowed to use} @Overridepublic void onproviderenabled ( String provider) {//When a location provider can use} @Overridepublic void Onstatuschanged (string provider, int status,bundle extras) {//when the state When a change occurs, the callback opens--close; close--Open}}}
The layout file is:
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=" com.andy.gpsdemo.MainActivity "> <textview android: Textsize= "22SP" android:layout_width= "wrap_content" android:layout_height= "Wrap_content " android:text= "@string/hello_world"/></relativelayout>
The permissions you need to join are:
<uses-permission android:name= "Android.permission.ACCESS_MOCK_LOCATION"/>//simulator test using
<uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION"/>
Android-developed mobile phone locator