Access to a "GeoPoint" out of the method "run()"
I need to access the value "pt" of method "run ()" out of this method. How I can do it?. Here's the method:
public void minimaDistancia(final ItemizedOverlay itemized)
{
final MyLocationOverlay myloc = new MyLocationOverlay(this,mapa);
myloc.enableMyLocation(); //Activamos actualización de la posición
myloc.enableCompass(); //Activamos la brújula
myloc.runOnFirstFix(new Runnable() {
public void run() {
GeoPoint pt = myloc.getMyLocation();
}
});
...
}
Thanks.
I need to access to the "min_dist" in this method:
public void processLocation(GeoPoint punto,ItemizedOverlay itemized)
{
double min_dist = 1000;
double dist_aux;
int i;
Location puntoA = new Location("Punto 1");
puntoA.setLatitude(punto.getLatitudeE6());
puntoA.setLongitude(punto.getLongitudeE6());
for(i=0;i<12;i++)
{
Location puntoB = new Location("Punto 2");
puntoB.setLatitude(itemized.getItem(i).getPoint().getLatitudeE6()/1E6);
puntoB.setLongitude(itemized.getItem(i).getPoint().getLongitudeE6()/1E6);
dist_aux = puntoA.distanceTo(puntoB)/1000;
dist_aux = (double)Math.round(dist_aux*100)/100;
if(dist_aux < min_dist)
min_dist = dist_aux;
}
minimun_distance = min_dist;
}
I want to get the minimun distance between my location and the nearest hospital (is a first aid application). I've tried to declare a global variable like this: public static double minimun_distance, but when I want to change it's value, simply doesn't do it. It doesn't change 开发者_开发问答the minumun_distance value in the assignment. I forgot to say that when I try to show a Toast in this method, the app crashes whit a RunTimeError (I see it in the Eclipse Debugger).
Thanks for the answers.
You should make an instance method that does the actual processing:
public void minimaDistancia(final ItemizedOverlay itemized)
{
final MyLocationOverlay myloc = new MyLocationOverlay(this,mapa);
myloc.enableMyLocation(); //Activamos actualización de la posición
myloc.enableCompass(); //Activamos la brújula
myloc.runOnFirstFix(new Runnable() {
public void run() {
processLocation(myloc.getMyLocation());
}
});
}
public void processLocation(GeoPoint pt)
{
...
}
EDIT: try this instead. I'm guessing that the location hasn't been set for some reason.
myloc.runOnFirstFix(new Runnable() {
public void run() {
android.location.Location lf = myloc.getLastFix();
processLocation(new GeoPoint((int)(lf.getLatitude()*1E6), (int)(lf.getLongitude()*1E6)));
}
});
Not sure what you are asking. Where are you putting the toast routine? Maybe you can use a global variable at the activity class level?
Edit - sorry about that. Should have put this at the end...
精彩评论