Android GPS Gpsbasics Project hacking

Source: Internet
Author: User

First, the reference source:

GPS Basic example-android Example

Http://androidexample.com/GPS_Basic__-__Android_Example/index.php?view=article_discription&aid=68&aaid =93

Second, Permission:

<android:name= "Android.permission.ACCESS_FINE_LOCATION"/>  <android:name= "Android.permission.INTERNET"/>

Third, Example:

 PackageCom.example.gpsbasics;Importandroid.location.Location;ImportAndroid.location.LocationListener;ImportAndroid.location.LocationManager;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.widget.Toast;Importandroid.app.Activity;ImportAndroid.content.Context; Public classMainactivityextendsActivityImplementsLocationlistener {PrivateLocationmanager Locationmanager; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); /********** get Gps location Service Locationmanager Object ***********/        /********** Get GPS Service Management Object ************/Locationmanager=(Locationmanager) Getsystemservice (Context.location_service); /*Parameters:first (Provider): The name of the provider with which to register : Registered name Second (mintime): The minimum time interval for notifications, in milliseconds . This field was only used as a hint to conserve power, and actual time between location updates could be greater or lesser tha                                 n this value. : The minimum notification interval, in milliseconds.               This field is used only as a power saver, and the actual time between location updates can be larger or smaller than the value. Third (mindistance): The minimum distance interval for notifications, in meters: Minimum interval notification , in milliseconds fourth (listener): a {#link locationlistener} whose onlocationchanged (location) method will is call Ed for every location update: the Onlocationchanged (location) method is called when each position is updated*/locationmanager.requestlocationupdates (Locationmanager.gps_provider,3000,//3 sec10, This); /********* After registration onlocationchanged method called periodically after each 3 sec ***********/    }        /************* called after each 3 sec **********/@Override Public voidonlocationchanged (location location) {//location.getlatitude (): Latitude//location.getlongitude (): DimensionString str = "Latitude:" +location.getlatitude () + "\nlongitude:" +Location.getlongitude ();        Toast.maketext (Getbasecontext (), str, toast.length_long). Show (); LOG.E ("Gpsbasics", "onlocationchanged."); } @Override Public voidonproviderdisabled (String provider) {/******** called when User off Gps *********/Toast.maketext (Getbasecontext (),"Gps turned off", Toast.length_long). Show (); } @Override Public voidonproviderenabled (String provider) {/******** called when User on Gps *********/Toast.maketext (Getbasecontext (),"Gps turned on", Toast.length_long). Show (); } @Override Public voidOnstatuschanged (String provider,intstatus, Bundle extras) {        //TODO auto-generated Method Stub            }}

Android GPS Gpsbasics Project hacking

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.