You have two seperate classes, and the LastFoundLocation is an
instance varioable of those classes, so when you make a new one in
ViewDidLoad, it's just making a blank one.

Try making it in the AppDelegate, then pass the LocationHelper
instance into the other class, and use it there. Don't make a new one
in the ViewDidLoad.

Also, the LocationManager is async, so it may not have found a
location by the time you get to ViewDidLoad - make sure you handle not
having one :)

So:

In AppDelegate:
LocationHelper helper;

In the FinishedLoading of AppDelegate:
helper = new LocationHelper();
helper.GetForCurrentLocation();


//you have this already - make the other view, and eventually open it....
OtherClass cls = new OtherClass();
cls.locationHelper = helper;


In the ViewDidLoad of a other class

if (locationHelper.HasFoundLocation)
{
  var test = lastFoundLocation.Longitude.ToString();
Console.WriteLine(test);
}

And change the LocationHelper to set a bool of HasFoundLocation to
true when it finds it.

A better way may be to rewrite the LocationHelper as a singleton
(google it :) ), so you only have one instance anywhere. And maybe
OtherClass could hook into an event/delegate on LocationHelper so
LocationHelper can tell it when it has something, not the other way
around.




On Wed, Nov 16, 2011 at 12:58, Mittchel Van Vliet <[email protected]> wrote:
> Hello everyone,
> Recently I started working with LocationServices but there goes something
> wrong.. I'm storing the current location in a property and I'm trying to get
> the value from that in a different class. The value gets filled, but when I
> try to get the value its empty.
> I copied the source code Nic Wise provided me and editted that, getting the
> location works perfectly but storing it and then retrieving it returns
> coordinates: 0, 0.
> The source code can be found here:
> http://pastebin.com/4aJcxyY5
> In the FinishedLoading of AppDelegate I am retrieving the position by:
> LocationHelper helper = new LocationHelper();
> helper.GetForCurrentLocation();
> In the ViewDidLoad of a other class I am trying to retrieve the information
> with:
> LocationHelper helper = new LocationHelper();
> var test = lastFoundLocation.Longitude.ToString();
> Console.WriteLine(test);
> I hope someone can assist me with my problem.
> Thanks in advance!
> Regards,
> Mittchel
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>



-- 
Nic Wise
t.  +44 7788 592 806 | @fastchicken | http://www.linkedin.com/in/nicwise
b. http://www.fastchicken.co.nz/

Nearest Bus: find when the next bus is coming to your stop. http://goo.gl/Vcz1p
mobileAgent (for FreeAgent): get your accounts in your pocket.
http://goo.gl/IuBU
Trip Wallet: Keep track of your budget on the go: http://goo.gl/ePhKa
London Bike App: Find the nearest Boris Bike, and get riding! http://goo.gl/Icp2
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to