Multiple location objects appear to get updated at the same time

14 views
Skip to first unread message

Craig Lang

unread,
Jan 14, 2016, 12:48:50 PM1/14/16
to CodenameOne Discussions, cr...@craigrlang.com

Hi All,

A am attempting to record a location with a LocationListener, saving the previous location object, then testing for a change in the location.
(Note: Planning to convert to geoFence, but that's another story)

For some reason, I am finding that when one location is changed, the other Location object also contains the updated value.
Here are some snippets of code that should give you an idea of what I'm trying to do (and hopefully, what I'm doing wrong):

Object initialization in start()
        baseLocation = new Location();
        presentLocation = new Location();
        previousLocation = new Location();


Object Declarations and get/put routines:
    private Location baseLocation;
    public void setBaseLocation( Location locArg ){ baseLocation = locArg; }
    public Location getBaseLocation(){return baseLocation;}
   
    private Location presentLocation;
    public Location getPresentLocation(){return presentLocation;}
    public void setPresentLocation( Location locArg ){ presentLocation = locArg; }
   
    private Location previousLocation;
    public Location getPreviousLocation(){return previousLocation;}
    public void setPreviousLocation( Location locArg ){ previousLocation = locArg; }


    class MyListener implements LocationListener
    {
        //
        // Display results on location change
        //
        public void locationUpdated(Location location)
        {
            System.out.println("locationUpdated listener call...");
            System.out.println("location arg = " + location.getLatitude() + "/" + location.getLongitude());
            System.out.println("CurrentLocation = "  + getPresentLocation().getLatitude()  + "/" + getPresentLocation().getLongitude());
            System.out.println("Previouslocation = " + getPreviousLocation().getLatitude() + "/" + getPreviousLocation().getLongitude());

            //
            // Save present location as previous and location argument as current value
            //
            setPreviousLocation(getPresentLocation());
            setPresentLocation(location);
 
           [.... other stuff....]

        }

        public void providerStateChanged( int newState )  {  }
    }


When I abruptly change the location on the location simulator, here is the result in the console window:

locationUpdated listener call...
location arg = 40.3354294837329/-73.47862924999998
CurrentLocation = 40.3354294837329/-73.47862924999998
Previouslocation = 40.3354294837329/-73.47862924999998

locationUpdated listener call...
location arg = 45.099999999999994/-93.19999999999997
CurrentLocation = 45.099999999999994/-93.19999999999997
Previouslocation = 45.099999999999994/-93.19999999999997


It looks like the all three Location objects are getting updated prior to the listener call.

Am I doing something wrong in declaring the Location objects?
Is there something I'm overlooking about how these work?


Essential Stats:
IDE: Ecliplse Mars
Desktop OS = Windows 8.1
Using Simulator


Thanks,
Craig


Shai Almog

unread,
Jan 14, 2016, 11:00:37 PM1/14/16
to CodenameOne Discussions, cr...@craigrlang.com
Hi,
I don't think we have access to these location objects so I don't see how this can happen from our side of the fence.
Reply all
Reply to author
Forward
0 new messages