[moved] a code snippet example. i ask question about it
Helo. i write the belowing code. This code runs correctly in my application. i want to ask this. "speed" and "course" variables on this code returns "NAN". Where do i make wrong?
The second question is that : the location updates become once in a minute, but i want to update once in 5-10 second. Is it possible ? Thanks.
[CODE]public void Connection () throws LocationException
{
if(istracking==false)
{
istracking=true;
screen.setCurrent(finf);
finf.append("Connecting......");
cr=new Criteria();
cr.setHorizontalAccuracy(25);
provider=LocationProvider.getInstance(cr);
if(provider!=null)
provider.setLocationListener(this,-1,-1,-1);
}
}
public void locationUpdated(LocationProvider provider, Location location)
{
upDate t=new upDate();
t.start();
}
public void providerStateChanged(LocationProvider provider, int newState) {
}
public class upDate extends Thread
{
public void run()
{
try
{
loc=provider.getLocation(60);
if(loc.isValid())
{
String s="";
finf.deleteAll();
coor=loc.getQualifiedCoordinates();
double lt=coor.getLatitude();
double lon=coor.getLongitude();
float course=loc.getCourse();
double speed=loc.getSpeed();
long time=loc.getTimestamp();
s="Langitude: "+lt+"\\nLongitute: "+lon+
"Course: "+course+"\Speed : "+speed+"\nTime: "+time;
finf.append(s);
}
}
catch(Exception ex)
{
}
}[/CODE]
Re: a code snippet example. i ask question about it
I would try the Wiki and find some already working sample codes from there. One thing that is definetely wrong with your code is at least the variable t that is local variable and thus is not valid after the function returns.
Re: a code snippet example. i ask question about it
What is the wrong on my code? "t" is local,but it is used at one place,and when it begins to run,(i think) thread is worked.Am i right?
Re: a code snippet example. i ask question about it
If you're asking somebody to spot an error in your code you should rather use the language specific forums. Whatever your problem is, it's Java related, not LBS.
Re: [moved] a code snippet example. i ask question about it
Hi, I don't want to comment on your code. Just answer your questions.:-)
Most GPS device has their own hardware specification, it defines the maximum refresh interval, accuracy and other possible parameters. The LBS API just gives an common rule that should be followed when implementing APIs. so, as developer you could only point out your preference behavior you want the hardware to perform. API implementation would do all its best to fulfill your requirements rather than exactly MATCH.
Re: [moved] a code snippet example. i ask question about it
it seems to me u are making a mess out of it :P
u are trying to implement a locatiolistener, which when returns a location u fire up a thread which doesnt even use that location, instead ur thread asks a new location with loc.getlocation(60)...
I'd say have a look at the wiki or even better have a look at the API specification...
there are two methods to obtain a location, one is using locationlistener and one is by directly asking for one, u are trying to use both in one piece of code, thats just asking for problems ;)
Re: [moved] a code snippet example. i ask question about it
helo. Thanks for anwers.
Tiger79, you had said that there are 2 methods for taking location. i use both of them in my code.Is this wrong? I ask because my code is working.It acquires longituse,latitude informations.Again thanks...
Re: [moved] a code snippet example. i ask question about it
sure it might work,
but it takes up more resources, it might get conflicting at some point, and why use 2 methods if hte info u are getting from both is practically the same ?