We provide complete mobile and web apps development solutions

Thursday, May 2, 2013

Get Gps Coordinates in android

package com.example.gps;

import android.location.Location;
import android.location.LocationManager;
import android.location.LocationListener;
import android.os.Bundle;
import android.content.Context;
import android.widget.TextView;
import android.widget.Toast;
import android.app.Activity;

public class MainActivity extends Activity {

    private Context context;
    double latitude;
    double longitude;
    Location location;
    LocationManager locationManager;
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv = (TextView) findViewById(R.id.textView2);
        LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        LocationListener mlocListener = new MyLocationListener();
        mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                mlocListener);
    }

    /* Class My Location Listener */
    public class MyLocationListener implements LocationListener {

        @Override
        public void onLocationChanged(Location loc) {

         loc.getLatitude();
            loc.getLongitude();

            String Text =  "Latitud = "
                    + loc.getLatitude() + "Longitud = " + loc.getLongitude();

            tv.setText(Text);

                }

        @Override
        public void onProviderDisabled(String provider) {
          
        }

        @Override
        public void onProviderEnabled(String provider) {
           }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {

        }
    }
}

0 coment�rios:

Post a Comment

Online Training

Your Name :
Your Email: (required)
Your Message: (required)

Powered by Blogger.

Recent Posts

Find Us On Facebook

Popular Posts