PDA

Ver la Versión Completa : [ CONSULTA ] Problema con Variables


JuanSantini_
18/07/12, 20:17:46
Hola que tal amigos, este es mi primer post, ya tengo varios meses dandome la vuelta por estos foros.
En estos momentos ando en proyecto y tengo un problema con mi app..

En un intent tengo un EditText donde tengo la variable (solo para checar), de ese intent al sumir un boton me manda a Google Maps, donde me da la ubicación en latitud y longitud, esas variables las quiero guardar y regresar al intent anterior y refrescar el edittext ya con la información en las variables ( es un Double, ya saben -90.009090990 ).

El caso es que siempre regresa vacío, o al menos no se refresca la información.

Es difícil por que siempre trabaje con Netbeans, y me guiaba con los Watches, pero con Eclipse no tengo Watches, no se donde estaría el error.

Si me pudieran ayudar muchas gracias!

Franco_MC
18/07/12, 22:32:18
Si gustas permite que vea tu clase y vemos en donde anda mal el código, quedo a tus ordenes

JuanSantini_
19/07/12, 00:43:09
Si gustas permite que vea tu clase y vemos en donde anda mal el código, quedo a tus ordenes

Esta es la class donde abro el Google Maps, con Geolocalización determino la latitud y la longitud y la guardo en la variable.


// RouteTracker.java
// Main MapActivity for the RouteTracker app.
package emi.movil;

import android.content.Context;
import android.location.Criteria;
import android.location.GpsStatus;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

public class RouteTracker extends MapActivity
{
private LocationManager locationManager; // gives location data
private MapView mapView; // displays a Google map
private MapController mapController; // manages map pan/zoom
private CustomOverlay customOverlay; // Overlay that shows route on map
private BearingFrameLayout bearingFrameLayout; // rotates the MapView
private PowerManager.WakeLock wakeLock; // used to prevent device sleep
private Location lastLocation;
private int MAP_ZOOM = 18; // Google Maps supports 1-21
private SeekBar seekBarZoom;
private TextView textViewZooming;
private EditText editTextLatitud;
private EditText editTextLongitud;
private double latitud;
private double longitud;
public static final String LATITUD = "LATITUD";
public static final String LONGITUD = "LONGITUD";

// Called when the activity is first created
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);

// create new MapView using your Google Maps API key
bearingFrameLayout = new BearingFrameLayout(this,
getResources().getString(R.string.google_maps_api_ key));

// add bearingFrameLayout to mainLayout
RelativeLayout relativeLayoutMap=
(RelativeLayout) findViewById(R.id.RelativeLayoutMap);
relativeLayoutMap.addView(bearingFrameLayout);

editTextLatitud = (EditText) findViewById(R.id.editTextLatitud);
editTextLongitud = (EditText) findViewById(R.id.editTextLongitud);

// get the MapView and MapController
mapView = bearingFrameLayout.getMapview();
mapController = mapView.getController(); // get MapController
mapController.setZoom(MAP_ZOOM); // zoom in the map

// create map Overlay
customOverlay = new CustomOverlay();

// add the CustomOverlay overlay
mapView.getOverlays().add(customOverlay);

textViewZooming = (TextView) findViewById(R.id.textViewZooming);

seekBarZoom = (SeekBar) findViewById(R.id.seekBarZoom);
seekBarZoom.setOnSeekBarChangeListener(seekBarList ener);

// register listener for trackingToggleButton
Button obtenerUbicacionButton =
(Button) findViewById(R.id.obtenerUbicacionButton);
obtenerUbicacionButton.setOnClickListener(obtenerU bicacionListener);
} // end onCreate

// called when Activity becoming visible to the user
@Override
public void onStart()
{
super.onStart(); // call super's onStart method

// create Criteria object to specify location provider's settings
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE); // fine location data
criteria.setBearingRequired(true); // need bearing to rotate map
criteria.setCostAllowed(true); // OK to incur monetary cost
criteria.setPowerRequirement(Criteria.POWER_LOW); // try to conserve
criteria.setAltitudeRequired(false); // don't need altitude data

// get the LocationManager
locationManager =
(LocationManager) getSystemService(LOCATION_SERVICE);

// register listener to determine whether we have a GPS fix
locationManager.addGpsStatusListener(gpsStatusList ener);

// get the best provider based on our Criteria
String provider = locationManager.getBestProvider(criteria, true);

// listen for changes in location as often as possible
locationManager.requestLocationUpdates(provider, 0, 0,
locationListener);

lastLocation = locationManager.getLastKnownLocation(provider);

if (lastLocation != null) {
latitud = lastLocation.getLatitude();
longitud = lastLocation.getLongitude();
editTextLatitud.setText(String.format(getResources ().getString(R.string.formateador_coordenada, (double) lastLocation.getLatitude())));
editTextLongitud.setText(String.format(getResource s().getString(R.string.formateador_coordenada, (double) lastLocation.getLongitude())));
GeoPoint point = new GeoPoint((int) (lastLocation.getLatitude() * 1E6), (int) (lastLocation.getLongitude() * 1E6));
// add the given Location to the route
customOverlay.update(point);

// move the map to the current location
mapController.animateTo(point);

// update the compass bearing
bearingFrameLayout.setBearing(lastLocation.getBear ing());
}

// get the app's power manager
PowerManager powerManager =
(PowerManager) getSystemService(Context.POWER_SERVICE);

// get a wakelock preventing the device from sleeping
wakeLock = powerManager.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK, "No sleep");
wakeLock.acquire(); // acquire the wake lock

bearingFrameLayout.invalidate(); // redraw the BearingFrameLayout
} // end method onStart

// called when Activity is no longer visible to the user
@Override
public void onStop()
{
super.onStop(); // call the super method
wakeLock.release(); // release the wakelock
} // end method onStop

// update location on map
public void updateLocation(Location location)
{
if (location != null) // location not null
{
// get the latitude and longitude
Double latitude = location.getLatitude() * 1E6;
Double longitude = location.getLongitude() * 1E6;
//latitud = latitude.doubleValue();
//longitud = longitude.doubleValue();

editTextLatitud.setText(String.format(getResources ().getString(R.string.formateador_coordenada, (double) location.getLatitude())));
editTextLongitud.setText(String.format(getResource s().getString(R.string.formateador_coordenada, (double) location.getLongitude())));

// create GeoPoint representing the given Locations
lastLocation = location;

GeoPoint point = new GeoPoint(latitude.intValue(), longitude.intValue());

// add the given Location to the route
customOverlay.update(point);

// move the map to the current location
mapController.animateTo(point);

// update the compass bearing
bearingFrameLayout.setBearing(location.getBearing( ));
bearingFrameLayout.invalidate(); // redraw based on bearing

} // end if
} // end method updateLocation

// responds to events from the LocationManager
private final LocationListener locationListener =
new LocationListener()
{
// when the location is changed
public void onLocationChanged(Location location)
{
updateLocation(location); // update the location
} // end onLocationChanged

public void onProviderDisabled(String provider)
{
} // end onProviderDisabled

public void onProviderEnabled(String provider)
{
} // end onProviderEnabled

public void onStatusChanged(String provider,
int status, Bundle extras)
{
} // end onStatusChanged
}; // end locationListener

// determine whether we have GPS fix
GpsStatus.Listener gpsStatusListener = new GpsStatus.Listener()
{
public void onGpsStatusChanged(int event)
{
if (event == GpsStatus.GPS_EVENT_FIRST_FIX) {
Toast results = Toast.makeText(RouteTracker.this,
getResources().getString(R.string.toast_signal_acq uired),
Toast.LENGTH_SHORT);

// center the Toast in the screen
results.setGravity(Gravity.CENTER,
results.getXOffset() / 2, results.getYOffset() / 2);
results.show(); // display the results
} // end if
} // end method on GpsStatusChanged
}; // end anonymous inner class

// Google terms of use require this method to return
// true if you're displaying route information like driving directions
@Override
protected boolean isRouteDisplayed()
{
return false; // we aren't displaying route information
} // end method isRouteDisplayed

// create the Activity's menu from a menu resource XML file
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.route_tracker_menu, menu);
return true;
} // end method onCreateOptionsMenu

// handle choice from options menu
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// perform appropriate task based on
switch (item.getItemId())
{
case R.id.mapItem: // the user selected "Map"
mapView.setSatellite(false); // display map image
return true;
case R.id.satelliteItem: // the user selected "Satellite"
mapView.setSatellite(true); // display satellite image
return true;
default:
return super.onOptionsItemSelected(item);
} // end switch
} // end method onOptionsItemSelected

// listener for trackingToggleButton's events
OnClickListener obtenerUbicacionListener =
new OnClickListener()
{
public void onClick(View arg0) {
getIntent().getExtras().putDouble(LATITUD, latitud);
getIntent().getExtras().putDouble(LONGITUD, longitud);

finish();
}
}; // end anonymous inner class

private OnSeekBarChangeListener seekBarListener = new OnSeekBarChangeListener() {

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
MAP_ZOOM = progress+1;
textViewZooming.setText("Zoom: " + String.valueOf(progress));
mapController.setZoom(MAP_ZOOM); // zoom in the map
updateLocation(lastLocation);
}

public void onStartTrackingTouch(SeekBar seekBar) {
}

public void onStopTrackingTouch(SeekBar seekBar) {
}

};

} // end class RouteTracker