none
[U8.1] Input string was not in a correct format when affecting longitude,lattitude to a Location in a universal app project RRS feed

  • Question

  • Hi,

    I am following this tutorial https://blogs.bing.com/maps/2012/11/05/getting-started-with-bing-maps-windows-store-apps-native/ to add icones to every Location in a map according to its longitude and lattitude from this web Service:

    (json format)

    {
    success: 1,
    total: 2,
    locals: [
    {
    id_local: "59",
    local_longi: "20",
    local_latit: "25894"
    },
    {
    id_local: "60",
    local_longi: "10.33699",
    local_latit: "25.997745"
    }
    ]
    }

    this is my code:

    private async void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
            {
                await
                            this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
    async () =>
                            {
                        UriS = "MyURL";
                        var http = new HttpClient();
                       http.MaxResponseContentBufferSize =Int32.MaxValue;
                       var response = await http.GetStringAsync(UriS);
                       var rootObject = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);
    
                     for(int i=0;i< int.Parse(rootObject.total); i++)
                       {
                      //Get the current location
                       Location[] location = new Location[2];
                       location[i] = new Location(double.Parse(rootObject.locals[i].local_latit), double.Parse(rootObject.locals[i].local_longi));  //I get the error here
    
                        //Update the position of the GPS pushpin
                        MapLayer.SetPosition(GpsIcon, location[i]);
    
                        //Set the radius of the Accuracy Circle
                   GpsIcon.SetRadius(args.Position.Coordinate.Accuracy);                 
    
                                //Make GPS pushpin visible
                                GpsIcon.Visibility = Windows.UI.Xaml.Visibility.Visible;
    
                                //Update the map view to the current GPS location
                                MyMap.SetView(location[i], 17);
    
                                }
                            }));}

    I get this error:

    Input string was not in a correct format

    at this line:

    location[i] = new Location(double.Parse(rootObject.locals[i].local_latit), double.Parse(rootObject.locals[i].local_longi));

     this Helps,this is the result of Debugging:

    so please how can I correct my code,to put icon according to its Location

    thanks for Help





    • Edited by Fred Bao Thursday, January 21, 2016 8:16 AM add the tag
    • Moved by Fred Bao Thursday, January 21, 2016 8:19 AM bing map sdk related
    Wednesday, January 20, 2016 11:26 PM

Answers

  • It sounds and looks like your issue is with your data. What is the values of rootObject.locals[i].local_latit and rootObject.locals[i].local_longi?

    Your error message says "Input string was not in a correct format", which is likely being thrown by the double.Parse function.

    In addition to checking the value of these properties, I would also recommend using double.TryParse to make your code much more stable.

    Also, why are you creating an array of Locations and only using the first value. Your code only needs a Location object and not an array.


    http://rbrundritt.wordpress.com

    Thursday, January 21, 2016 4:13 PM

All replies

  • Hello tamtam200,

    From your description, you are using the Bing Map SDK, I would help move it to the Bind Map SDK forum for getting better help.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 21, 2016 8:18 AM
  • It sounds and looks like your issue is with your data. What is the values of rootObject.locals[i].local_latit and rootObject.locals[i].local_longi?

    Your error message says "Input string was not in a correct format", which is likely being thrown by the double.Parse function.

    In addition to checking the value of these properties, I would also recommend using double.TryParse to make your code much more stable.

    Also, why are you creating an array of Locations and only using the first value. Your code only needs a Location object and not an array.


    http://rbrundritt.wordpress.com

    Thursday, January 21, 2016 4:13 PM