Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] GPS geolocation

Então na verdade nao verifiquei o logcat, porem eu queria que aparecesse nos edittext os valores da longitude e latitude porem não aparece.

Fiz a conversão de doble pra string, pois o getLatidute e getLongitude retornam double correto?



2011/12/6 Matheus Bodo <mcbodo@gmail.com>
Olá Luis,

Qual o erro que está dando? Aparece algo no Logcat?

Você adicionou a permissão ACCESS_FINE_LOCATION no AndroidManifest.xml?

[]s


On Mon, Dec 5, 2011 at 4:18 PM, luiszacheu <luiszacheu@gmail.com> wrote:
Olá a todos, estou tentando montar uma app que pegue os valores de
latitude e longitude e quando acionado um evento em um buttun atribua
esses valores em edittexts.
abaixo o codigo que eu estou fazendo, alguem sabe me dizer em que
estou errando?
public class principal extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);
       Button btGetLocation =  (Button)
findViewById(R.id.btGetLocation);
       btGetLocation.setOnClickListener(new View.OnClickListener() {
                       public void onClick(View v) {
                               // TODO Auto-generated method stub
                               // AndroidManifest.xml must have the
following permission:
                               // <uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
                               LocationManager locationManager =
(LocationManager)
getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, new LocationListener() {
                                       public void
onStatusChanged(String provider, int status, Bundle
extras) {
                                               // called when the
provider status changes. Possible status:
OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or AVAILABLE.
                                       }
                                       public void
onProviderEnabled(String provider) {
                                               // called when the
provider is enabled by the user
                                       }
                                       public void
onProviderDisabled(String provider) {
                                               // called when the
provider is disabled by the user, if it's
already disabled, it's called immediately after
requestLocationUpdates
                                       }
                                       public void
onLocationChanged(Location location) {
                                               //double latitute =
location.getLatitude();
                                               //double longitude =
location.getLongitude();
                                               // do whatever you
want with the coordinates
                                               EditText x =
(EditText) findViewById(R.id.edLocationX);
                                               EditText y =
(EditText) findViewById(R.id.edLocationY);

x.setText(String.valueOf(location.getLatitude()));

y.setText(String.valueOf(location.getLongitude()));
                                       }
                               });
                       }
               });
   }



--
Matheus Augusto Bodo




--
Atenciosamente,
Luís Gustavo Verri Zacheu
luiszacheu@gmail.com

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário