because the project to use GPS positioning, learning the next, then the learning results recorded.
To add permissions in the manifest file:
<uses-permission android:name= "Android.permission.ACCESS_COARSE_LOCATION" ></uses-permission> <uses-permission android:name= "Android.permission.ACCESS_FINE_LOCATION" ></uses-permission> < Uses-permission android:name= "Android.permission.INTERNET" ></uses-permission> <uses-permission Android:name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission>
several objects used, Locationmanager, Locationlistener, location.
*locationmanager Location Manager, you must first create a Locationmanager object if you want to manipulate the device.
Locationmanger locationmanager= (Locationmanager) This.getsystemservice (Context.location_service);
* Locationlistener position Listener, monitor position change, monitor device switch and status. Used primarily to obtain location, in the inner class implementation:
Class Mylisten implements Locationlistener { @Override public void onlocationchanged (location location) { //Position changed LOG.I (TAG, "onlocationchanged ..."); if (Mhandler! = null) { Message msg = mhandler.obtainmessage (refresh_location, location); Msg.sendtotarget (); } } @Override public void onproviderdisabled (String provider) { // } @Override public Void Onproviderenabled (String provider) { } @Override public void Onstatuschanged (string provider, int Status, Bundle Extras) { // } }
Binding monitoring:
Mylistengps = new Mylisten (); Locationmanager.requestlocationupdates (Locationmanager.gps_provider, check_position_interval, 0, MyListenGPS );
4 parameters in Requestlocationupdates (String provider, long mintime, float mindistance, Locationlistener listener):
String provider: Device provider, Locationmanager.gps_provider, and Locationmanager.network_provider
Long mintime: Update period of position information, in milliseconds;
Float mindistance: Position change minimum Distance: Position information is updated when the location distance changes beyond this value
Locationlistener Listener: Supervisor Listener
* location information, such as time, latitude and longitude, altitude, etc. can be obtained through location.
Location Location=locationmanager.getlastknownlocation (locationmanager.gps_provider);// Active acquisition of Locationsimpledateformat DateFormat = new SimpleDateFormat ("yyyy mm month DD Day HH:mm:ss"); Date date = new Date (Location.gettime ()); String message = "Time:" + dateformat.format (date) + "\ n" + "Longitude:" + location.getlongitude () + "\ n" + "Latitude:" + location . Getlatitude () + "\ n";
Android GPS Learning