Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6062795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:05:33+00:00 2026-05-23T09:05:33+00:00

What with tombstoning, serialisation is pretty central to WP7 apps. And location based apps

  • 0

What with tombstoning, serialisation is pretty central to WP7 apps. And location based apps are all the rage. But when I tried to put a GeoCoordinate into isolated storage settings, it failed to rehydrate later, and I ended up serialising lat and lng independently, which is highly unsatisfactory as I’ve ended up with boatloads of ad hoc serialisation code. I’ve cleaned it up somewhat using reflection, but really it’s all a big mess.

What’s the deal here? Is there a Right Way that I haven’t learnt?

And if not, what were the writers of the GeoCoordinate class thinking? Annotation with the DataMember attribute is all it would have taken. Did it never cross their minds that locations might be part of app state in a WP7 app?

I’ve already seen this piece on serialisation and isolated storage files as well as this rather more interesting piece which links to a rather basic DIY binary serialisation helper (Microsoft’s BinaryFormatter class is not available).

Mango includes Silverlight4, or so I’m told (my notebook doesn’t have enough RAM, and she who must be obeyed has forbidden me to build a bigger system till after our August ski trip) – does anyone know whether this means BinaryFormatter will be available? I could reproduce BinaryFormatter but I’d rather not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:05:34+00:00Added an answer on May 23, 2026 at 9:05 am

    Although I maintain my opinion that Microsoft should exercise some common sense and ensure that classes like GeoCoordinate are DataContract serialisable, I have found a convenient workaround. Generally when one is doing this sort of work, one has imported the interface for the BingRoute webservice, or similar.

    Obviously all of the classes therein are serialisable so I converted all my code to use the BingRoute.Location type instead of GeoCoordinate, and the problem disappears. Where necessary, an extension method ToGeoCoordinate() makes the conversion sufficiently unobtrusive that the intent of existing code is unobscured.

    public static GeoCoordinate ToGeoCoordinate(this BingRoute.Location loc)
    {
      return new GeoCoordinate(loc.Latitude, loc.Longitude, loc.Altitude);
    }
    

    If you take my advice then sooner or later you will miss GeoCoordinate’s GetDistanceTo() method. Extension methods are your friend here too.

    You could convert both points to GeoCoordinate and use the built-in method, but this will produce large numbers of transient objects and at some point your app will choke while the garbage collector does its duty.

    I threw in the other built-in location type for good measure. Note that the distance code implements Haversine, which is a Great Circle computation with a number of limitations. Caveat emptor.

    public static double GetDistanceTo(this BingRoute.Location A, BingRoute.Location B)
    {
      return GetDistanceTo(A.Latitude, A.Longitude, B.Latitude, B.Longitude);
    }
    
    public static double GetDistanceTo(
      this Microsoft.Phone.Controls.Maps.Platform.Location A, 
      Microsoft.Phone.Controls.Maps.Platform.Location B)
    {
      return GetDistanceTo(A.Latitude, A.Longitude, B.Latitude, B.Longitude);
    }
    
    static double toRad = Math.PI / 180D;
    static double toDeg = 180D / Math.PI;
    
    static double GetDistanceTo(double lat1, double lng1, double lat2, double lng2)
    {
      lat1 *= toRad;
      lng1 *= toRad;
      lat2 *= toRad;
      lng2 *= toRad;
      double sin_dLng_on2_squared = Math.Sin((lng2 - lng1) / 2);
      sin_dLng_on2_squared *= sin_dLng_on2_squared;
      double sin_dLat_on2_squared = Math.Sin((lat2 - lat1) / 2);
      sin_dLat_on2_squared *= sin_dLat_on2_squared;
      double a = sin_dLat_on2_squared + Math.Cos(lat1 * Math.Cos(lat2) * sin_dLng_on2_squared);
      double c = 2 * Math.Asin(Math.Min(1, Math.Sqrt(a)));
      return c * 6371000;
    }
    

    It’s also quite important to note that the more you store, the slower your app starts because it takes longer to create the settings object on activation. So you’re best advised to store only simple option state here and keep as much as possible in isolated storage files.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm digging into tombstoning of WP7 but haven't found sufficient information on when
i've just run into the infamous tombstoning problem/issue in WP7. let's say i have
I am handling tombstoning in Wp7 by dumping my ViewModel into the PhoneApplicationService state
A general question regarding tombstoning WP7 applications. What do you think a users expectations
I read a lot about application states, tombstoning and recommended practises but I am
I have a WP7 application that I've disabled the idle capabilities of the phone
I have seen the word Tombstoning in many tutorials. I did not get what
I'm just learning about how to navigate between pages and tombstoning. I'm wondering if
With multi-tasking enabled, can I safely throw away tombstoning when porting my project to
I'm building a WP7 app, and I'm now at the point of handling the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.