geolocation - Location doesn't work in my mobile with Android -


i'm developing app android generates sms obtaining current location of user. have done app can't detect location , appears toast have created "fallo2"

i'm testing app in real mobile phone.

what problem?

class main

@override     public void onclick(view view) {     switch (view.getid()) {     case r.id.enviarmensajebutton:         if(obtenertelefonos()){             if(obtenerlocalizacion()){                 generarmensaje();             }             else{                 toast.maketext(this, "fallo2", toast.length_long).show();             }         }         else{             toast.maketext(this, "fallo", toast.length_long).show();         }          break;     case r.id.menubutton:         intent configuracionintent = new intent(mainactivity.this, configuracion.class);         startactivity(configuracionintent);         break;     } }  private boolean obtenertelefonos(){     return true; }  private boolean obtenerlocalizacion() {     gps gps = new gps(this);     int = 0;     while(!gps.obtenerlocation()){         i++;         if(i > 100){             return false;         }     }     if(gps.obtenerdireccion()){         codigopostal = gps.codigopostal;         direccion = gps.direccion;         ciudad = gps.ciudad;         pais = gps.pais;         latitude = string.valueof(gps.latitude);         longitude = string.valueof(gps.longitude);         return true;     }     else{         return false;     } }  private void generarmensaje(){     tv.settext(codigopostal+"  "+direccion+"  "+ciudad+"  "+pais+"  "+latitude+"  "+longitude); } 

class gps

public class gps implements locationlistener { private context context; public double latitude, longitude; public string codigopostal, direccion, ciudad, pais; private locationmanager locationmanager; public location bestlocation; private list<string> providers; public list<address> direcciones;  public gps(context context) {     this.context = context;     locationmanager = (locationmanager) context             .getsystemservice(context.location_service); }  public boolean obtenerlocation() {     try {         providers = locationmanager.getallproviders();         bestlocation = null;         (string provider : providers) {             location location = locationmanager.getlastknownlocation(provider);             if(location == null) continue;             if(bestlocation == null || location.getaccuracy() < bestlocation.getaccuracy()){                 bestlocation = location;             }         }         if(bestlocation != null){             return true;         }         else{             return false;         }     } catch (exception e) {         return false;     } }  public boolean obtenerdireccion() {     try {         // obtenemos la longitud y la latitud del objeto location          latitude = bestlocation.getlatitude();         longitude = bestlocation.getlongitude();          // creamos un objeto geocoder indicando nuestro lenguaje         //locale spanish = new locale("es", "es");         geocoder geocoder = new geocoder(this.context, locale.english);          // partir de geocoder obtenemos una lista de direcciones         direcciones = geocoder.getfromlocation(latitude,                 longitude, 1);          // obtenemos todos los datos que necesitamos         codigopostal = direcciones.get(0).getpostalcode();         direccion = direcciones.get(0).getaddressline(0);         ciudad = direcciones.get(0).getaddressline(1);         pais = direcciones.get(0).getaddressline(2);          return true;     } catch (exception e) {         return false;     } }  @override public void onlocationchanged(location arg0) {  }  @override public void onproviderdisabled(string arg0) {  }  @override public void onproviderenabled(string arg0) {  }  @override public void onstatuschanged(string arg0, int arg1, bundle arg2) {  }} 

i have added permissions in manifest file , need obtaining 1 location.

did add correct permissions in manifest file? need post more code in order

@override public void onlocationchanged(location arg0) {  } 

method empty - means after gps signal has been recieved nothing information - should use new location got update user's location, try , use this guid more guidance can more guidance gps class this thread


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -