BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-10-2008, 09:44 AM   #1 (permalink)
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  
Old 08-10-2008, 11:53 AM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

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.
Offline  
Old 08-10-2008, 12:21 PM   #3 (permalink)
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

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.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright © 2004-2014 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.