BlackBerry Forums Support Community

BlackBerry Forums Support Community (
-   Developer Forum (
-   -   Can't stop Coordinates from updating (

kmdcomp 08-10-2008 08:44 AM

Can't stop Coordinates from updating
Hi Everyone, I'm kind of relearning java as I go along here, so please excuse any unconventional coding practices, but feel free to point them out to me, I havenít used java in many years :?

I wanted to play around with GPS on my blackberry 8830 from Verizon. So I bought at BT GPS puck and everything is good there.

I'm trying to modify the GPSDemo project that came with the JDE. I stripped out the stuff that I didn't need, server connection, waypoints, etc...

All I want to accomplish is for the program to show the current position as I move and the speed. This is working already and was left over from the original app.

I also want to be able to mark a point, then move a bit and mark a second point and get the distance between the 2 points. This is where I'm having trouble. The program is returning the GPS info just fine and every time it sends some data I'm storing it in Location object called currentLocation.

When I click on a menu option, it should set the first point and when I click again, it should set the second point. Instead, after I set the first point, it keeps changing when new GPS info comes in and when I set point 2, it does the same thing. Both points are constantly synchronized to the currentLocation.


//global veriables to store GPS data
    private Location currentLocation;
    private Coordinates loc1;
    private Coordinates loc2;

//called whenever gps data comes in
public void updateLoc(Location l)
        currentLocation = l; 

//called whenever the markPosition menu button is selected
 private void setLoc()
            //if the first point has not been selected yet
            //then set loc1 to the current coordinates and set
          //pointMarked to true
            if(pointMarked == false)
                pointMarked = true;
                loc1 = currentLocation.getQualifiedCoordinates();
            //Otherwise, set loc2 to current and set pointmarked to false
                pointMarked = false;
                loc2 = currentLocation.getQualifiedCoordinates();
                distance = loc2.distance(loc1);

//Impementation of the locationListner class
private class LocationListenerImpl implements LocationListener
        // Members ----------------------------------------------------------------------------------------------
        private int captureCount;
        private int sendCount;
        // Methods ----------------------------------------------------------------------------------------------
        * @see javax.microedition.location.LocationListener#locationUpdated(LocationProvider,Location)
        public void locationUpdated(LocationProvider provider, Location location)
                float heading = location.getCourse();
                double longitude = location.getQualifiedCoordinates().getLongitude();
                double latitude = location.getQualifiedCoordinates().getLatitude();
                float altitude = location.getQualifiedCoordinates().getAltitude();
                float speed = location.getSpeed();               
              // Information to be displayed on the device.
                StringBuffer sb = new StringBuffer();
                sb.append("Longitude: ");
                sb.append("Latitude: ");
                sb.append("Altitude: ");
                sb.append(" m");
                sb.append("Heading relative to true north: ");
                sb.append("Speed : ");
                sb.append(" m/s");
                sb.append("Grade : ");
                //call method to update the global currentLocation
        public void providerStateChanged(LocationProvider provider, int newState)
            // Not implemented.

hrbuckley 08-10-2008 10:53 AM

Made the same mistake when I started. The Location API is giving you a reference to an internal object. You need to make a new one to store the values:

loc1 = new QualifiedCoordinates(currentLocation.getQualifiedC oordinates().getLatitude(), ...);

Tedious but it works. If someone has a better way I would like to see it as well.

kmdcomp 08-10-2008 11:21 AM

Thanks hrbuckley, I figured it had to be something like that. I'll give it a try, but I suspect it's going to work.

All times are GMT -5. The time now is 11:22 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.