java - Disappearing parameters from method -
i'm developping android application think might java specific.
from fragment call static method. in fragment set paramters static method. when debug app parameters set when static method paramters not set.
this method fragment (it's happening in calling of gpstracker.distanceinmetersfromto
):
public void updatedistance(location location) { latitude = location.getlatitude(); longtitude = location.getlongitude(); list<listinspectieitem> newlist = new arraylist<listinspectieitem>(); list<listinspectieitem> oldlist = adapter.getvalues(); (listinspectieitem l : oldlist) { double latitudefrom = latitude; double longtitudefrom = longtitude; double latitudeto = double.valueof(l.latitude); double longtitudeto = double.valueof(l.longtitude); double afst = gpstracker.distanceinmetersfromto( latitudefrom, longtitudefrom, latitudeto, longtitudeto ); newlist.add(new listinspectieitem( l.inspectiesoort, l.opdrachtidentificatie, l.bronsysteem, l.latitude, l.longtitude, round(afst, 2) )); } ... adapter.changelist(newlist); }
this static method:
public static double distanceinmetersfromto(double latitudefrom, double longtitudefrom, double latitudeto, double longtitudeto){ double r = 6371e3; // metres double phi1 = doubletoradian(latitudefrom); double phi2 = doubletoradian(latitudeto); double deltaphi = doubletoradian(latitudefrom-latitudeto); double deltadelta = doubletoradian(longtitudefrom-longtitudeto); double = math.sin(deltadelta/2) * math.sin(deltaphi/2) + math.cos(phi1) * math.cos(phi2) * math.sin(deltadelta/2) * math.sin(deltadelta/2); double c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)); return r * c; }
the parameters latitudefrom
, longtitudefrom
both set latitudeto
, longtitudeto both not set.
when call method variable have value. have no idea i'm doing wrong, might java magic don't know of.
update:
to clarify bit more here 2 screenshots during debug:
the call static method fragment. can see paramters set.
this static method distanceinmetersfromto
can see latitudefrom
, longtitudefrom
set.
have tried using parsedouble(l.latitude)
instead of double.valueof(l.latitude)
? latter returns double
object, while former returns primitive double
data type of variable you've assigned it. autounboxing should've taken care of that, it's worth try.
Comments
Post a Comment