none
MapControl.GetOffsetFromLocation doesn't work on Windows 10 Mobile 15063.608 RRS feed

  • Question

  • This is easy to reproduce on a Lumia 950. It does not reproduce in the 15063.137 emulator. Might be an ARM vs x86 thing?

    Anyway, the symptoms are fairly simple. Render a map, center it somewhere, then call GetOffsetFromLocation on the map center. On desktop Windows 10, this returns a real offset which one can then use to e.g. place XAML elements. But on mobile Windows 10 (at least on my phone) this always returns -1,-1.

    Anyone have a workaround?

    Thanks.

    Friday, October 6, 2017 9:28 PM

Answers

  • It looks like the Center property is returning an invalid value for altitude. If you just copy this and use it with an unspecified altitude reference system in the GetOffsetFromLocation call you'll get an error. It's always good practice to make sure you're using the right altitude reference system.

                BasicGeoposition pos = mainPageMapControl.Center.Position;
                pos.Altitude = 0; // if you omit this line you'll get an error
                Geopoint location = new Geopoint(pos);
                Point offset;
                mainPageMapControl.GetOffsetFromLocation(location, out offset);

    • Marked as answer by mfeingol Tuesday, October 10, 2017 12:54 AM
    Monday, October 9, 2017 3:49 PM
    Moderator

All replies

  • It looks like the Center property is returning an invalid value for altitude. If you just copy this and use it with an unspecified altitude reference system in the GetOffsetFromLocation call you'll get an error. It's always good practice to make sure you're using the right altitude reference system.

                BasicGeoposition pos = mainPageMapControl.Center.Position;
                pos.Altitude = 0; // if you omit this line you'll get an error
                Geopoint location = new Geopoint(pos);
                Point offset;
                mainPageMapControl.GetOffsetFromLocation(location, out offset);

    • Marked as answer by mfeingol Tuesday, October 10, 2017 12:54 AM
    Monday, October 9, 2017 3:49 PM
    Moderator
  • That appears to work. Thanks very much.
    Tuesday, October 10, 2017 12:54 AM