none
setting multiple Locations in a bing Map RRS feed

  • Question

  • Hi,

    I am having a problem in putting a marker for every location in my bing map, this is my code:

    private async void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
    {
        await
        // Need to get back onto UI thread before updating location information
        this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(
        async () =>
        {
            UriString4 = "my URL";
            var http = new HttpClient();
            http.MaxResponseContentBufferSize = Int32.MaxValue;
            var response = await http.GetStringAsync(UriString4);
            var rootObject = JsonConvert.DeserializeObject<NvBarberry.Models.RootObject>(response);
            Location[] location = new Location[int.Parse(rootObject.total)];
            for (int i = 0; i < int.Parse(rootObject.total); i++)
            {
                //Get the current location
    
                location[i] = new Location(rootObject.locals[i].local_latit,rootObject.locals[i].local_longi);
    
                //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);
    
            }
        }));}

    This is the JSON data from where I want to get the local_longi and local_latit of every Location:

    {
        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"
            }
        ]
    }

    The problem is that I get only one marker on the map,this is what I get when debugging: 

    from the Debugger,I get all results in "location" variable,I don't know why I get only one marker in the Map

    Please How can I correct my code to have multiple Locations in the Map

    this is the tutorial that I have followed: https://blogs.bing.com/maps/2012/11/05/getting-started-with-bing-maps-windows-store-apps-native/

    thanks for help



    Thursday, January 28, 2016 8:38 AM

Answers

  • Looks like you are confusing some things here. You started off with code for showing the location of a device via GPs, but then have data to create pushpins from. It looks like you don't want the GPS stuff. Loop through each item in your array and create a Pushpin object and add it to the map using code: https://msdn.microsoft.com/en-us/library/dn495616.aspx

    That said, it looks like you are creating a Windows 8 app. You should really target Windows 10 instead as all users are moving to that fast. Also, there is a brand new map control in Windows 10 and the map control you are using is deprecated. Here is info on the new map control: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn642089.aspx


    http://rbrundritt.wordpress.com

    Friday, January 29, 2016 12:29 AM
  • Those articles show you what you need. This is a really simple thing to do. Lets assume that you have an object that has the same structure as the JSON you posted stored in a variable called results, here is a quick code block:

    for(int i=0;i<results.locals.length; i++){
    	var pin = new Pushpin();
    	MapLayer.SetPosition(pin, new Location(results.locals[i].local_latit,results.locals[i].local_longi));
    	MyMap.Children.Add(pin);
    }
    
    That said, it looks like the lat/long values in the first item in the locals array has invalid values. Latitude should be between -90and 90, longitude between -180 and 180.


    http://rbrundritt.wordpress.com

    Sunday, January 31, 2016 5:36 PM

All replies

  • any help please I didn't found a solution for my problem
    Thursday, January 28, 2016 9:52 PM
  • Looks like you are confusing some things here. You started off with code for showing the location of a device via GPs, but then have data to create pushpins from. It looks like you don't want the GPS stuff. Loop through each item in your array and create a Pushpin object and add it to the map using code: https://msdn.microsoft.com/en-us/library/dn495616.aspx

    That said, it looks like you are creating a Windows 8 app. You should really target Windows 10 instead as all users are moving to that fast. Also, there is a brand new map control in Windows 10 and the map control you are using is deprecated. Here is info on the new map control: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn642089.aspx


    http://rbrundritt.wordpress.com

    Friday, January 29, 2016 12:29 AM
  • thanks Sir for your reply,I have seen those links,they didn't help me,what I want is to set multiples locations on a Map with Bing Maps in which I have problem :(
    Sunday, January 31, 2016 12:43 AM
  • Those articles show you what you need. This is a really simple thing to do. Lets assume that you have an object that has the same structure as the JSON you posted stored in a variable called results, here is a quick code block:

    for(int i=0;i<results.locals.length; i++){
    	var pin = new Pushpin();
    	MapLayer.SetPosition(pin, new Location(results.locals[i].local_latit,results.locals[i].local_longi));
    	MyMap.Children.Add(pin);
    }
    
    That said, it looks like the lat/long values in the first item in the locals array has invalid values. Latitude should be between -90and 90, longitude between -180 and 180.


    http://rbrundritt.wordpress.com

    Sunday, January 31, 2016 5:36 PM