package com.example.Maps013;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
 
public class Geolocalisation01 extends Activity implements LocationListener 
{
 
	private LocationManager locationManager;
	
	TextView tv_latitude, tv_longitude, tv_altitude;
 
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
 
		super.onCreate(savedInstanceState);
		setContentView(R.layout.geolocation_layout);
 
		locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
 
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, this);
		
		tv_latitude = (TextView) findViewById(R.id.tv_latitude);
		tv_longitude = (TextView) findViewById(R.id.tv_longitude);
		tv_altitude = (TextView) findViewById(R.id.tv_altitude);
	}
 
	@Override
	public void onLocationChanged(Location location) {
 
		double latitude = location.getLatitude();
		double longitude = location.getLongitude();
		double altitude = location.getAltitude();
		
		//latitude = round(latitude, 4); 	
		//latitude = round(latitude, 4); 	
		//latitude = round(latitude, 2 ); 	
		
		
		tv_latitude.setText( Double.toString(latitude) );
		tv_longitude.setText( Double.toString(longitude) );
		tv_altitude.setText( Double.toString(altitude) );
		
		
		//String msg = "New Latitude: " + location.getLatitude()
		//		+ "New Longitude: " + location.getLongitude();
 
		//Toast.makeText(getBaseContext(), msg, Toast.LENGTH_LONG).show();
	}
 
	

	@Override
	public void onProviderDisabled(String provider) 
	{
 
		Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
		startActivity(intent);
		Toast.makeText(getBaseContext(), "Gps is turned off!! ",
				Toast.LENGTH_SHORT).show();
	}
 
	@Override
	public void onProviderEnabled(String provider) {
 
		Toast.makeText(getBaseContext(), "Gps is turned on!! ",
				Toast.LENGTH_SHORT).show();
	}
 
	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
 
	}
 
}