-2

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) {

        }
    }

}
ricriba
  • 11
  • 4

2 Answers2

0

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!

ricriba
  • 11
  • 4
0
private void moveToCurrentLocation() {
    Criteria criteria = new Criteria();
    LocationManager locationManager = (LocationManager) getContext().getSystemService(LOCATION_SERVICE);
    String provider = locationManager.getBestProvider(criteria, true);
    if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    Location location = locationManager.getLastKnownLocation(provider);
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();
    LatLong latLong = new LatLong(latitude, longitude);
    CameraPosition cameraPosition = new CameraPosition()
            .target(latLong).zoom(whateverZoomThatYouWant);
    map.animateCameraTo(cameraPosition);
}

// that is for fragment if you use it in activity delete --> getContext()