Analysis of three kinds of GSM mobile phone positioning technology in Android _android

Source: Internet
Author: User
Copy Code code as follows:

Declaring Locationmanager objects
Locationmanager Loctionmanager;
Access to Locationmanager objects through system services
Loctionmanager = (Locationmanager) getsystemservice (Context.location_service);

Mode one:
Copy Code code as follows:

Get location via GPS location provider
String Providergps = Locationmanager.gps_provider;
Location Location = loctionmanager.getlastknownlocation (PROVIDERGPS);

Mode two:
Copy Code code as follows:

Get location from Base station location provider
String providernetwork = Locationmanager.network_provider;
Location Location = loctionmanager.getlastknownlocation (providernetwork);

Mode three:
Copy Code code as follows:

Use standard collections to allow the system to automatically select the best available location provider and provide location
Criteria criteria = new criteria ();
Criteria.setaccuracy (criteria.accuracy_fine);//High precision
Criteria.setaltituderequired (false);/No elevation required
Criteria.setbearingrequired (false);/No Azimuth required
Criteria.setcostallowed (TRUE);//Allow cost
Criteria.setpowerrequirement (Criteria.power_low);/Low power consumption
Match the best provider of the above criteria from the available location providers
String Provider = Loctionmanager.getbestprovider (criteria, true);
Get the last change position
Location Location = loctionmanager.getlastknownlocation (provider);


Processing:
Copy Code code as follows:

Show in EditText
Updatewithnewlocation (location);
Monitoring position change, 2 seconds, distance 10 meters or more
Loctionmanager.requestlocationupdates (provider, 1000, 1, Locationlistener);

Listeners and display:
Copy Code code as follows:

//position Listener
Private final Locationlistener Locationlistener = new locationl Istener () {
@Override
public void onstatuschanged (String provider, int status, Bundle extras) {
}
@Override
public void onproviderenabled (String provider) {
}
@Override
public void Onproviderdisab LED (String provider) {
}
///When position changes trigger
@Override
public void onlocationchanged (Location Location) {
//Use the new location update TextView display
Updatewithnewlocation (location);
}
};
private void Updatewithnewlocation (Location Location) {
if (Location!= null) {
Double lat = location.getl Atitude ();
Double LNG = location.getlongitude ();
Latstr = Format.format (LAT);
Lonstr = Format.format (LNG);
Txtlat.settext (LATSTR);
Txtlon.settext (LONSTR);
} else {
Txtlat.settext ("");
Txtlon.settext ("");
}
}
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.