How to check the range of latitude/longitude values in the creation of a BasicGeoposition

Yesterday I  experimented the following error displaying some pushpins on a map using the great Joost library:

            public static void Set_WpWinNl_Maps_MapShapeDrawBehavior_ItemsSource(global::WpWinNl.Maps.MapShapeDrawBehavior obj, global::System.Collections.Generic.IEnumerable<global::System.Object> value, string targetNullValue)
                if (value == null && targetNullValue != null)
                    value = (global::System.Collections.Generic.IEnumerable<global::System.Object>) global::Windows.UI.Xaml.Markup.XamlBindingHelper.ConvertValue(typeof(global::System.Collections.Generic.IEnumerable<global::System.Object>), targetNullValue);
                <strong>obj.ItemsSource = value;</strong>

InnerException: “Value does not fall within the expected range.”

Strack trace:

   at Windows.Devices.Geolocation.Geopoint..ctor(BasicGeoposition position)
   at WpWinNl.Maps.MapIconDrawer.CreateShape(Object viewModel, BasicGeoposition pos)
   at WpWinNl.Maps.MapShapeDrawBehavior.CreateDrawable(Object viewModel, Object locationData)
  at WpWinNl.Maps.MapShapeDrawBehavior.CreateShape(Object viewModel)
   at WpWinNl.Maps.MapShapeDrawBehavior.AddNewShapes(IEnumerable viewModels)
   at WpWinNl.Maps.MapShapeDrawBehavior.ItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at Windows.UI.Xaml.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at WpWinNl.Maps.MapShapeDrawBehavior.set_ItemsSource(IEnumerable`1 value)
   at Urbelog10.Views.MainPage.XamlBindingSetters.Set_WpWinNl_Maps_MapShapeDrawBehavior_ItemsSource(MapShapeDrawBehavior obj, IEnumerable`1 value, String targetNullValue)
   at Urbelog10.Views.MainPage.MainPage_obj1_Bindings.Update_ViewModel_Pushpins(ObservableCollection`1 obj, Int32 phase)
   at Urbelog10.Views.MainPage.MainPage_obj1_Bindings.Update_ViewModel(MainPageViewModel obj, Int32 phase)
   at Urbelog10.Views.MainPage.MainPage_obj1_Bindings.Update_(MainPage obj, Int32 phase)
   at Urbelog10.Views.MainPage.MainPage_obj1_Bindings.Update()

Because I received the coordinates walues from REST service that I converted in BasicGeopositions (no error in the creation of that objects), I started to think that there could be a “strange” limitation in the number of pushpins that one can ask to be displayed with that library (may be for performance reasons)  …


Then I realized that the problem came from the REST service that give one position where the comma is missing in the latitude and longitude values!!

   "latitude": 451390400000000,
   "longitude": 77703090000000,

What I found strange is that the conversion from lat/long to BasicGeoposition did not arise an error when creating the object with not valid latitude and longitude values …

bizEntity.GeoPosition = new BasicGeoposition { Altitude = 0, Latitude = dcEntity.latitude, Longitude = dcEntity.longitude };

But I realized that you can put whatever value to a BasicGeoposition object … they are simply Double and there is no check of consistency!! I supposed that some check would done … but on the contrary BasicGeoposition is a simple struct without a constructor that could make some check … so I I realized that I have to do myself a check of the incoming data. before creating each BasicGeoposition object … and possibly make that data consistent …



namespace Windows.Devices.Geolocation {
    [ContractVersion(typeof(UniversalApiContract), 65536)]
    public struct BasicGeoposition {
        public System.Double Altitude;
        public System.Double Latitude;
        public System.Double Longitude;

This is a possible way to do the applopriate check in order to be sure that a created BasicGeoposition object is a valid one:

  //public Double latitude { get; set; }
        private Double _latitude;
        public Double latitude {
            get { return _latitude; }
            set {
                if (value < -90 || value > 90) {
                    throw new ArgumentOutOfRangeException("Latitude must be between -90 and 90 degrees inclusive."); // or whatever
                _latitude = value;

        //public Double longitude { get; set; }
        private Double _longitude;
        public Double longitude {
            get { return _longitude; }
            set {
                if (value < -180 || value > 180) {
                    throw new ArgumentOutOfRangeException("Longitude must be between -180 and 180 degrees inclusive.");// or whatever
                _longitude = value;



Informazioni su Enzo Contini

Electronic engineer
Questa voce è stata pubblicata in Windows, Windows Phone/Mobile. Contrassegna il permalink.

Lascia un Commento/Leave a comment

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:


Stai commentando usando il tuo account Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...