Android: get Current Location using GPS

person Jason Huangfolder_openAndroidlocal_offer, , access_time September 29, 2010
	private void GetCurrentGPSInfo() {
 
		 LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
			 	public void onStatusChanged(String provider, int status, Bundle extras) {
			 		// called when the provider status changes. Possible status: OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or AVAILABLE.
			 	}
			 	public void onProviderEnabled(String provider) {
			 		ShowMessage("GPS is enabled.");
			 		// called when the provider is enabled by the user
			 	}
			 	public void onProviderDisabled(String provider) {
			 		ShowMessage("GPS is disabled.");
			 		// called when the provider is disabled by the user, if it's already disabled, it's called immediately after requestLocationUpdates
			 	}
 
			 	public void onLocationChanged(Location location) {
			 		double latitute = location.getLatitude();
			 		double longitude = location.getLongitude();
			 		double altitude = location.getAltitude();
 
			 		// do whatever you want with the coordinates
			 		tv_alt.setText(Double.toString(altitude));
			 		tv_long.setText(Double.toString(longitude));
			 		tv_lat.setText(Double.toString(latitute));
 
			 	}
		 });
 
	}

Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>