I cannot seem to load coordinates from a text file and create a pushpin

I cannot seem to load coordinates from a text file and create a pushpin

I have posted this issue HERE over at stack overflow, but couldnt get any help.

My problem is that I cannot seem to load coordinates from a text file and create a pushpin to that place.  Here is the code that is giving me problems:

            try
            {
                //Read the file from the specified location.
                fileReader = new StreamReader(new IsolatedStorageFileStream("latitude.txt", FileMode.Open, fileStorage));
                //Read the contents of the file (the only line we created).
                string carlatitude = fileReader.ReadToEnd();
               
                fileReader = new StreamReader(new IsolatedStorageFileStream("longitude.txt", FileMode.Open, fileStorage));
                //Read the contents of the file (the only line we created).
                string carlongitude = fileReader.ReadToEnd();
                fileReader.Close();

                carlocation = new GeoCoordinate(carlatitude, carlongitude);

                Pushpin car = new Pushpin();
                car.Background = new SolidColorBrush(Colors.Green);
                car.Foreground = new SolidColorBrush(Colors.Black);
                car.Content = "You Parked Here";
                car.Tag = "carPushpin";
                car.Location = carlocation;
                this.map.Children.Add(car);
                this.map.SetView(watcher.Position.Location, 18.0);

            }
            catch
            {
                MessageBox.Show("Debug Errror-no cords.txt");
            }

Any help will be greatly appreciated.

Also, if you can simplify your answers, that'd be great! (Fairly new to coding)

Your "carlatitude" and "carlongitude" variables are type string but the constructor for GeoCoordinate needs these values to be of type double.

You can convert from string to double using Convert.ToDouble(...) but these functions can also throw exception if the string is empty or if the content cannot be parsed.

ex:

double dLat = Convert.ToDouble(carlatitude);
double dLon = Convert.ToDouble(carlongitude);

carlocation = new GeoCoordinate(dLat, dLon);

Copyright © 2007-2012 www.chuibin.com Chuibin Copyright