Cached data?


#1

Hello,

I had a few problems grasping this chapter, but i guess the points i’m feeling are a little blurry will clear up after practice and more reading in further chapters. I won’t go as far as to re-read the entire chapter… yet :slight_smile:

anywhoo, i don’t at all understand why we must make an NSTimeInterval, and check if the data is more than 3 minutes old? the method is called when a new location is found, and we only look for a new location when we press the return key on our keyboard (or move 20 meters, or whatever limit we set). So, why would it have to do that check?

Thanks.


#2

CLLocationManager will immediately return you a location if it has found one before. For example, if you have ever hopped on an airplane, landed, and opened up Maps you will notice that the blue dot starts at your origin and then quickly updates to your new location. This is because iOS caches your last location for immediate return while it figures out your current location.

Since this application is designed to grab the first location found, the cached data isn’t what we want. This makes sure to ignore data that is 3 minutes old - chances are, you didn’t go that far in 3 minutes.


#3

I see, so this will actually only update, if it have not updated to a new location in 3 minutes?

So, a CLLocation returns the last location found you say, but isn’t that clarified as the “old” location? Why is the “new” location then cached? Wouldn’t it be better if it was just the old location?

For instance, we can specify how often we want to update. Say we want to update after having moved 50 meters. We start at meter 1, and when we now moved to meter 50 we have 2 locations: old location: 1 meter and new location: 50 meters, yes?

In that case, we don’t ever have cached data, do we? We always move at least 50 meters before updating, and as such we should have a new location? it’s a little blurry to me how it works. Thanks for helping.


#4

No, it will always update. If the location was just found, it’s going to be less than 3 minutes old so it will always pass that check.

When a location object is prepared, it is timestamped and cached. It doesn’t matter what application does this - Whereami, Maps, Facebook, whatever - that location object is stored as the “last location found.”

When a location manager is created and told to start updating, it will return the last location found immediately, while it works on getting the real location.


#5

Thanks for trying to help me out, really appreciate it, and i hate myself for finding this so hard to understand.

i just don’t seem to understand it at all. I mean, why? You say it will always return a location, while it is looking for a new location, so when the method is executed, it is actually always using an “old” data location, while it looks for a new one?

Its really blurry to me. Maybe i have to read it again :frowning:


#6

Uh, uh, maybe i got it now, after a good nights sleep. :slight_smile:

So, the CLLocationManager will return the last location found, while it works on getting a new location update, yes? So it can provide the user with some feedback right away.

The application we made, also just returns the last location found, but we don’t want that, and we simply wait for it to have actually found a new location to show us? So the application we made, will not return the last location like “Maps” does, but will simply not return anything if the data is cached? ie. more than 3 minutes old?

i ALMOST got it i think :stuck_out_tongue:


#7

Right, the location manager is rigged up to continuously deliver location updates to its delegate. The first update it delivers will happen almost immediately, because instead of actually determining the location, it uses the last location determined (by any app). This is to give the user a sense of feedback and is useful for applications like Maps, where the blue dot is always moving to give you your current position, so being off for a few seconds doesn’t matter (because it will either update to the new position soon, or you are close enough to the cached location, so it won’t matter).

However, in this app, we want to grab the location as it stands when the text is entered, so we have to disregard this cached data.


#8

Ah now i think i got it.

So it is “global” so to speak. I mean, it will take the last location discovered on the device, regarding of the app that determined it to give a feedback right away. Since we don’t want this, we tell it to ignore data that is 3 minutes old, as this would mean it is cached data, and not what we want for our application?

I actually think it’s starting to stick now, at least if what i wrote above is just partially true :slight_smile:


#9

Yup, you are right. And 3 minutes is pretty arbitrary number we just picked… we figure you can’t move too far in 3 minutes.