On the principle of mobile phone positioning of Android phone defender _android

Source: Internet
Author: User
Tags garbage collection md5 encryption

Recommended reading:

An analysis of Android phone defender SIM card binding

An in-depth analysis of the Android phone defender MD5 encryption when saving passwords

Detailed Android Phone Guardian Settings Wizard page

An analysis of Android phone defender turn off automatic Updates

A brief analysis of Android phone defender custom control properties

An analysis of Android phone defender reading contacts

On the Android handset Guardian receives the short message instruction to carry on the corresponding operation

Mobile phone positioning of three ways: network positioning, base station positioning, GPS positioning

network positioning, mobile phone Wi-Fi 2g 3g, the mobile phone will have an IP, the error is very large

Base station positioning, accuracy and the number of base station, dozens of meters to a few kilometers of error

GPS positioning, requires at least three satellites to locate, in the open space accurate

Mobile phone use A-GPS need network to assist positioning, fast positioning, the network recorded the last satellite orbit,

Gets the Locationmanager object, through Getsystemservice (Location_service)

Invokes the Requestlocationupdates () method of the Locationmanager object, requesting location updates, parameters:

Positioning mode ("GPs"), Update Time (60000), update distance (x), Locationlistener object

Locationlistener is an interface that needs to do its implementation class

Define Mylocationlistener implementation Locationlistener, implement the method below it

Onlocationchanged (), when the position changes the callback, passing in a Location object

Call the Location object's Getlongitude () method to get the longitude

Call the Location object's Getlatitude () method to get the dimension

Call the Location object's Getaccuracy () method to get the precision

Onstatuschanged (), when the state changes when the callback, turn off the open

Onproviderenabled (), when a location provider is available

Onproviderdisabled (), when a location provider is unavailable

Cancel the listening position when the activity is destroyed

Rewrite the activity's OnDestroy () method

Call the Locationmanager object's Removeupdates (), cancel the listener, Parameters: Locationlistener Object

Set the Locationlistener object to null, garbage collection

The permissions Required

Android.permission.ACCESS_FINE_LOCATION Get Accurate location
Android.permission.ACCESS_COARSE_LOCATION get a rough position
Android.permission.ACCESS_MOCK_LOCATION gets the location of the simulation (when the simulator is developed)

On the simulator, the DDMS inside sends the following position to display

The state to the coordinates of the offset processing, to become the Mars coordinates, the need for the mapping bureau Plug-ins, the network has Mars coordinate conversion code

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 Prot ected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.activity_main);
Gets the 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) {//Get longitude String longitude= "Longitude:" +location.getlongitude ();
String latitude= "Latitude:" +location.getlatitude ();
String acc= "precision:" +location.getaccuracy (); Toast.maketext (Mainactivity.this, Longitude+latITUDE+ACC, 1). Show (); @Override public void onstatuschanged (String provider, int status, Bundle extras) {} @Override public void Onprovideren Abled (String provider) {} @Override public void onproviderdisabled (string provider) {}}}

The above is a small set to introduce the Android phone Guardian mobile phone positioning principle, I hope to help you!

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.