Current Location android

Issue

I’ve been following some tutorials and creating some simple android apps but I’m having some trouble with that one it only consists in showing the current location (longitude, latitude, altitude).

Any ideas about whats going on? Thanks in advance!

package com.ricard.location.app;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity {

    TextView textLat;
    TextView textLong;
    TextView textAlt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textLat  (TextView) findViewById(R.id.textLat);
        textLong  (TextView) findViewById(R.id.textLong);
        textAlt  (TextView) findViewById(R.id.textAlt);

        LocationManager lm  (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        LocationListener ll  new mylocationlistener();
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
    }
    class mylocationlistener implements LocationListener{

        @Override
        public void onLocationChanged(Location location){
            if(location ! null)
            {
                double plong  location.getLongitude();
                double plat  location.getLatitude();
                double palt  location.getAltitude();

                textLat.setText(Double.toString(plat));
                textLong.setText(Double.toString(plong));
                textAlt.setText(Double.toString(palt));

            }


        }

        @Override
        public void onStatusChanged(String s, int i, Bundle bundle) {

        }

        @Override
        public void onProviderEnabled(String s) {

        }

        @Override
        public void onProviderDisabled(String s) {

        }
    }

}

Solution

There was an error with the reception of the signal on this device I tested it on a new one and it worked so it was a Hardware error thought.

Thanks!

Answered By – ricriba

Leave a Comment