android--User Positioning

Source: Internet
Author: User

User orientation (i)

User location and Google Maps are the basis of navigation software and cannot be used to

GPS American Motorola, the civilian positioning in about 20 meters.

Telecom: Signal Reception tower,

1. What can User location be used for?
    1. Get the user's location
    2. Track users ' movements
2. Two key APIs for User Locaiton

Location Manager: User targeting services for managing Android

Location Providers: Available in three ways, two of which are the most common,

GPS Positioning: Android.permission.ACCESS_FINE_LOCATION

Network positioning: Signal reception tower and WiFi reception point for positioning, android.permission.ACCESS_FINE_location (relatively accurate) or android.permission.ACCESS_coarse_location (imprecise)

Passive positioning: Passive positioning, not much use

3. Get the user's current location (most commonly used)

Third, the general steps to achieve:

1. Define Permissions in Androidmanifest.xml

2. Get Locationmanager Object

3. Select Locationprovider

4. Bind the Locationlistener object (a time will be triggered when the position is moved)

Four, code reference:

Androidmanifest.xml

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Max.userlocation"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "7" />    <uses-permissionAndroid:name= "Android.permission.ACCESS_FINE_LOCATION" />    <ApplicationAndroid:icon= "@drawable/ic_launcher"Android:label= "@string/app_name" >        <ActivityAndroid:name=". Userlocation "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>

Userlocation.java

 Packagemax.userlocation;Importandroid.app.Activity;Importandroid.location.Location;ImportAndroid.location.LocationListener;ImportAndroid.location.LocationManager;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button; Public classUserlocationextendsActivity {/**Called when the activity is first created.*/Button userlocationbtn=NULL; @Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.main); USERLOCATIONBTN=(Button) Findviewbyid (R.id.buttonid); Userlocationbtn.setonclicklistener (NewUserlocationbtnlistener ()); }    classUserlocationbtnlistenerImplementsOnclicklistener {@Override Public voidOnClick (View arg0) {//TODO auto-generated Method StubLocationmanager Locationmanager =(Locationmanager) Mainactivity.this. Getsystemservice (Context.location_service);
Define the currently used positioning method, one is the time (how long to update the location, just a reference value), one is the distance (minimum distance). The binding listener. Locationmanager. requestlocationupdates (Locationmanager.gps_provider,0, 0,NewUserlocationlistener ()); } } classUserlocationlistenerImplements Locationlistener {//When the location of the device changes, this method is called the @Override of the double type Public voidonlocationchanged (location location) {//TODO auto-generated Method StubSystem.out.println ("Longitude:" +location. Getlongitude ()); System.out.println ("Latitude:" +location. Getlatitude ()); } @Override Public voidonproviderdisabled (String provider) {//TODO auto-generated Method Stub}//@Override Public voidonproviderenabled (String provider) {//TODO auto-generated Method Stub}//When the state changes @Override Public voidOnstatuschanged (String provider,intstatus, Bundle extras) { //TODO auto-generated Method Stub } }}

4, using DDMS simulation positioning

The simulator has no GPS effect, but there are methods.

android--User Positioning

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.