View Single Post
Old 08-10-2008, 08:44 AM   #1 (permalink)
kmdcomp
New Member
 
Join Date: Apr 2008
Model: 8830
PIN: N/A
Carrier: verizon
Posts: 9
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't stop Coordinates from updating

Please Login to Remove!

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.


Code:
//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
            else
            {
                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)
        {
            if(location.isValid())
            {
                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(longitude);
                sb.append("\n");
                sb.append("Latitude: ");
                sb.append(latitude);
                sb.append("\n");
                sb.append("Altitude: ");
                sb.append(altitude);
                sb.append(" m");
                sb.append("\n");
                sb.append("Heading relative to true north: ");
                sb.append(heading);
                sb.append("\n");
                sb.append("Speed : ");
                sb.append(speed);
                sb.append(" m/s");
                sb.append("\n");
                sb.append("Grade : ");
               
                GPSDemo.this.updateLocationScreen(sb.toString());
                
                 //call method to update the global currentLocation
                 GPSDemo.this.updateLoc(location);
            }
        }
  
        public void providerStateChanged(LocationProvider provider, int newState)
        {
            // Not implemented.
        }        
    }
Offline   Reply With Quote