[Android] the principle of mobile location of mobile guards
There are three ways of mobile phone positioning: network positioning, base station positioning and GPS positioning
For network positioning, when the mobile phone is connected to WiFi 2g 3g, the mobile phone will have an IP, with great error
The accuracy of base station positioning is related to the number of base stations, with an error of tens of meters to several kilometers
GPS positioning requires at least three satellites to locate accurately in open places
The mobile phone uses A-GPS and needs the network to assist in positioning. The positioning speed is fast. The network records the last satellite orbit,
Get the locationmanager object through getsystemservice (location_service)
Call the requestlocationupdates() method of the locationmanager object to request location updates. Parameters:
Positioning method ("GPS"), update time (60000), update distance (50), locationlistener object
Locationlistener is an interface, and its implementation class needs to be made
Define mylocationlistener and implement the following methods
Onlocationchanged(), when the location changes, the callback passes in a location object
Call the getlongitude () method of the location object to get the longitude
Call the getlatitude () method of the location object to get the dimension
Call the getaccuracy () method of the location object to get the accuracy
Onstatus changed(), when the status changes, the callback is turned off and on
Onproviderenabled(), when a location provider is available
Onproviderdisabled(), when a location provider is unavailable
When the activity is destroyed, the listening location is cancelled
Override the ondestroy () method of the activity
Call removeupdates() of locationmanager object to cancel listening. Parameter: locationlistener object
Set the locationlistener object to null and garbage collection
Required permissions
android.permission.ACCESS_ FINE_ Location get accurate location
android.permission.ACCESS_ COARSE_ Location gets the rough location
android.permission.ACCESS_ MOCK_ Location get the location of the simulation (when the simulator is developed)
On the simulator, the following positions can be displayed only after being sent in DDMS
The state has biased the coordinates and turned them into Martian coordinates, which requires the plug-in of the National Bureau of Surveying and mapping. There is a Martian coordinate conversion code on the Internet