Hello everybody,
I would like re-read a KML file with the GPS. As the inside-GPS
eclipse don't manage altitude (cf my last post) i decided to create a
thread that do it.
So, i have a service that Listen my provider GPS "simulation" and i
would like create the thread that set coordonate information for
"simulation" provider.
But in my thread with this line :
monLocationManager = (LocationManager) getSystemService
(Context.LOCATION_SERVICE);
Eclipse says that getSystemService is undefined
So, i found a solution that works but i think it's not very very
beautiful and i think i haven't to do that :
I declare a locationManager in my thread's class and in my service, i
affect the locationManager of my service to the location manager of my
thread.
here is my code (simplified with only code interesting) of the
service:
public class ServiceGPS extends Service {
// variables declaration
public LocationManager monLocationManager = null;
simuThread monSimuThread;
[ others variables.... ]
public class MonBinder extends Binder
{ServiceGPS getService(){return ServiceGPS.this;}}
@Override
public IBinder onBind(Intent arg0) {return new MonBinder();}
@Override
public void onStart(Intent MonIntent, int startId)
{
monLocationManager = (LocationManager) getSystemService
(Context.LOCATION_SERVICE);
[ .... some code ... ]
monSimuThread = new simuThread();
monSimuThread.monLocationManager = monLocationManager; // <==
HERE !!
monSimuThread.start();
monLocationListener = new LocationListener()
{
public void onLocationChanged(Location maLocation)
{
double maLatitude = maLocation.getLatitude();
double maLongitude = maLocation.getLongitude();
double monAltitude = maLocation.getAltitude();
Intent MonIntent = new Intent
(EVENT_NOUVELCOORD);
MonIntent.putExtra("latitude",
String.valueOf(maLatitude));
[... other putExtra ...]
ServiceGPS.this.sendBroadcast(MonIntent);
} // fin onLocationChanged
[ .... some code ... ]
} // fin LocationListener
monLocationManager.requestLocationUpdates(provider,
60000,
500,monLocationListener);
super.onStart(MonIntent, startId);
} // fin onStart
}
**************************************************************************
here is my code for the thread :
public class simuThread extends Thread {
// Variables Declaration
LocationManager monLocationManager = null;
[ others variables.... ]
public void run()
{
try
{
while (!arretThread)
{
Thread.sleep(1000);
Location maLocation = new Location("simulation");
maLocation.setAltitude(1000);
maLocation.setLatitude(2.87566);
maLocation.setLongitude(48.456456);
monLocationManager.setTestProviderLocation("simulation", maLocation);
}
}
catch (Exception e)
{[ .... some code ... ]}
super.run();
} // fin run
}
Can somewone tell me how i can do that more beautifully ???
Thx a lot
Cedric
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---