I am using Nokia Prototype 4.0,NetBeans6.0 for building an application for Nokia N82 in J2ME Polish. I am trying to update user's Location through GPS on Screen. I have implemented LocationListener's Functionality in a class named DeviceLocation and I am passing current Form's Object as a Parameter to it so that I can Update the Form from DeviceLocation Class. The Form I am using is J2Me Polish Form. here is the code snippet from Midlet Class which is calling DeviceLocation's getPosition(). . StringItem textString = new StringItem("","Getting GPS Data...."); Form textViewForm= new Form("Text View Form" ); textViewForm.append(textString); display.setCurrent(this.textViewForm); deviceLocation.getPosition(textViewForm);
In Device Location I have written code to get Coordinates and to update the Form on basis of that. It is running fine on Nokia Emulator it updates the Screen(Form) in specified time Interval but the Update never Happens on Real Device(Nokia N82). I am not getting the cause of it wheather it is some Security Problem or Form could not be updated like this. I have tried to append() text to Form and also tried to change the text of StringItem both didn't work the Form doesn't update and Neither shows any Exception or alert. If anyone Suggest the Problem or another Approach, it would be a great help for me. The code of DeviceLocation Class is as follows:
public class DeviceLocation implements LocationListener {
public LocationProvider provider; public Location location; public QualifiedCoordinates qc; private Coordinates coordinates; Form textViewForm; String textString; StringItem strItem = new StringItem("","Getting GPS Data....");
// getPosition() taking Form as Parameter public void getPosition(Form form) { try { this.showTextViewForm = form; Criteria cr = new Criteria(); cr.setHorizontalAccuracy(500); cr.setVerticalAccuracy(500); provider = LocationProvider.getInstance(cr); provider.setLocationListener(this, 60, 10, 20); // set locationListener to Listen on time Interval } catch (Exception e) { e.printStackTrace(); } } public void locationUpdated(final LocationProvider prov, final Location loc) { new Thread() {
public void run() { try { if (loc != null && loc.isValid()) { qc = loc.getQualifiedCoordinates(); double lat = qc.getLatitude(); double lng = qc.getLongitude(); textString = DisplayRecord.calculateDistence();// calculate distance on basis of current Lat/Long strItem.setText(textString);//change text of StringItem textViewForm.set(0, strItem);//replace String Item, here I have tried deleteAll() and append() also but doesn't work } else {
} }catch (Exception ex) { ex.printStackTrace(); }
} }.start(); }
public void providerStateChanged(LocationProvider prov, int newState) { } }
Where do you get the GPS data from? Are you connected to the GPS, or are you inserting dummy data? I'd start with the latter, then try to see if the display is updated...
What I mean is: are you completely sure that your app communicates correctly with the GPS; and therefore that you are dealing with a GUI issue? Try to isolate the problem.
The emulator doesn't help much in these cases... you must try on the device.
Problem is not from the GPS as we can get different lat/long. Also in our approach we have added a refresh button which is calling to the same page and it is working fine. But from the listener, it is not repainting for the different lat/long
I do not have control on listener thread. As refresh button in itself is working fine so now I trying another approach. Now I am creating a different thread when it is reaching to any form. This thread is calling refresh function. Now whenever I am going out of this form, I am stopping this thread. Let me try this approach and then I will update you
One more thing in my initial approach, this was working fine on the emulator but not on the real device.