Analysis on the principle of mobile phone positioning of Android mobile phone guard
- 2021-07-03 00:55:18
- OfStack
Recommended reading:
Analysis of Android Mobile Phone Guardian sim Card Binding
In-depth analysis of md5 encryption when Android mobile phone guard saves password
Explanation of Android Mobile Guardian Setup Wizard Page
Analysis of Android Mobile Phone Guardian Turning off Automatic Update
Analysis on the Attributes of Android Mobile Guardian Custom Control
Analysis on Android Mobile Phone Guardian Reading Contacts
Analysis on Android mobile phone guards receiving short message instructions and executing corresponding operations
There are three ways of mobile phone positioning: network positioning, base station positioning and GPS positioning
Network positioning, when the mobile phone is connected to wifi 2g 3g, the mobile phone will have an ip, which has a big error
Base station positioning, the accuracy is related to the number of base stations, and the error from 10 meters to several kilometers
GPS positioning requires at least 3 satellites to locate and is accurate in open places
Mobile phones using A-GPS need network to assist positioning, which is fast. The network records the last satellite orbit.
Gets the LocationManager object via getSystemService (LOCATION_SERVICE)
Call the requestLocationUpdates () method of the LocationManager object and request a location update with the following parameters:
Location mode ("gps"), update time (60000), update distance (50), LocationListener object
LocationListener is an interface and needs to be its implementation class
Define MyLocationListener to implement LocationListener and implement the following methods
onLocationChanged (), callback when position changes, passing in 1 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
onStatusChanged (), callback when state changes, closed on
onProviderEnabled (), when a 1 location provider is available
onProviderDisabled (), when a 1 location provider is unavailable
Cancel the listening location when activity is destroyed
Override the onDestroy () method of activity
Call removeUpdates () of LocationManager object and cancel listening. Parameter: LocationListener object
Set the LocationListener object to null, garbage collection
Required permissions
android.permission.ACCESS_FINE_LOCATION Get Precise Position
android. permission. ACCESS_COARSE_LOCATION Get the rough position
android. permission. ACCESS_MOCK_LOCATION Get the location of the simulation (when the simulator was developed)
On the simulator, ddms can send the following locations before it can be displayed
The country has biased the coordinates and changed them into Mars coordinates, which requires the plug-in of the State Bureau of Surveying and Mapping, and there is a Mars coordinate conversion code on the Internet
package com.tsh.mylocation;
import android.app.Activity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
public class MainActivity extends Activity {
private LocationManager lm;
private LocationListener listener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get Location Manager
lm=(LocationManager) getSystemService(LOCATION_SERVICE);
listener=new MyLocationListener();
lm.requestLocationUpdates("gps", 0, 0, listener);
}
private class MyLocationListener implements LocationListener{
@Override
public void onLocationChanged(Location location) {
// Obtain longitude
String longitude=" Longitude: "+location.getLongitude();
String latitude=" Latitude: "+location.getLatitude();
String acc=" Accuracy: "+location.getAccuracy();
Toast.makeText(MainActivity.this, longitude+latitude+acc, 1).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
}
The above is the site to introduce the Android mobile phone guard mobile phone positioning principle, I hope to help you!