locked
v8 bing maps RRS feed

  • Question

  • I am having issues implementing multiple pushpins from a database this worked in v7 but now i only get my location  

    does v8 support arrayed pins?

    do all the push pins have to be passed before the map is loaded

    is it possible to do a for i for (var r=1,<count; r++)

    and add pushpins

    do the push pin need to be pushed individually or all at once

    thanks

    Ron


    • Edited by Ronc1 Saturday, July 2, 2016 8:43 PM
    Saturday, July 2, 2016 8:38 PM

Answers

  • Ricky

    i am still having problems i think that i have the way i pass the gps wrong because i can get it with the test example but not with the gps

    does this look close?

     console.log(results.rows.item(r).Lat, results.rows.item(r).Lon)
                        loca[r] = parseFloat(results.rows.item(r).Lat)
                        loc[r] = parseFloat(results.rows.item(r).Lon);
                        


                   // var pushpins = Microsoft.Maps.TestDataGenerator.getPushpins(10, map.getBounds())
                     // var  locat= new Microsoft.Maps.Location(45.231658, -69.492536)
                      var pushpins =  new Microsoft.Maps.Pushpins(45.231658 , -69.492536);

                        console.log(loca[r], loc[r])

                        layer.add(pushpins)
                        
                            //Add a pushpin at the user's location.
                           
                         //   map.entities.push(pin);
                    }
                    map.layers.insert(layer)
                        

    • Marked as answer by Ronc1 Friday, July 15, 2016 11:54 PM
    • Unmarked as answer by Ronc1 Friday, July 15, 2016 11:57 PM
    • Marked as answer by Ronc1 Friday, July 15, 2016 11:58 PM
    Friday, July 15, 2016 2:17 AM
  • In the code above only one pushpin is created and added to the layer. However the pushpin is not created correctly. You need to create a Location object. For example

    var pushpins =  new Microsoft.Maps.Pushpins(new Microsoft.Maps.Location(45.231658, -69.492536));


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Friday, July 15, 2016 3:14 PM
    • Marked as answer by Ronc1 Friday, July 15, 2016 11:58 PM
    Friday, July 15, 2016 3:14 PM

All replies

  • yes, you can use an array of pushpins with v8. You can either loop through them and add them or simply pass in the whole array. Can you provide the code you are trying to use that isn't working.


    [Blog] [twitter] [LinkedIn]

    Sunday, July 3, 2016 3:15 PM
  • Thank you here is a snippet 

    i want to pull from a database and then populate the map 

    i have noticed v8 is a little slower at loading then v7 is there something i am doing wrong?

    for (var r = 1; r < count; r++) {

                        navigator.geolocation.getCurrentPosition(function (position) {

                            var loc = new Microsoft.Maps.Location(

                                position.coords.latitude,

                                position.coords.longitude);

                            //Add a pushpin at the user's location.

                            var pin = new Microsoft.Maps.Pushpin(loc);

                            map.entities.push(pin);

    //above test for pushpin which works

                        })

                        console.log(results.rows.item(r).Lat, results.rows.item(r).Lon)

                        loca[r] = (results.rows.item(r).lat)

                        loc[r] = (results.rows.item(r).Lon);

                        console.log(loc)

                        var gt = r.toString()

                        // pin[r] = (loc);

                        pina[r] = { text: gt }

                        pin[r] = new Microsoft.Maps.Pushpin(loca[r], loc[r]);

                        layer.add(pin[r])

     map.layers.insert(layer)

    //code below is for the infobox (this worked in v7

                        var tj = (results.rows.item(r).Name)

                        var ty = (results.rows.item(r).Address)

                        var tp = (results.rows.item(r).Bait)

                        var te = (results.rows.item(r).Phone)

                        console.log(ty)

                        //  var pin = new Microsoft.Maps.Pushpin(lat2, lon2);

                        // map.layers.insert(layer)

                       

    thank you for your time

    i get an html1300 info box when it runs

    Ron


    • Edited by Ronc1 Sunday, July 3, 2016 10:10 PM
    Sunday, July 3, 2016 10:08 PM
  • When loading an info box, where are you getting r? Also, infoboxes are no longer added to the map.entities or entitycollections in v8. Instead you do info box.setMap(map).


    [Blog] [twitter] [LinkedIn]

    Monday, July 4, 2016 3:59 AM
  • Ricky

    r comes from the count in the database

    Right now i am more concerned with the multiple push pins i get the first one ( from the example) so i know i am making it to this section of code but i dont get any others t give me a html 1300

                    var layer = new Microsoft.Maps.Layer()

                    var count = results.rows.length;//(from database)

                    console.log(count)

                    var loc = new Array(count)

                    var loca = new Array(count)

                    var pin = new Array(count)

                    var pina = new Array(count

    for (var r = 1; r < count; r++) {

                        navigator.geolocation.getCurrentPosition(function (position) {

                            var loc = new Microsoft.Maps.Location(

                                position.coords.latitude,

                                position.coords.longitude);

                            //Add a pushpin at the user's location.

                            var pin = new Microsoft.Maps.Pushpin(loc);

                            map.entities.push(pin);// this pin works

                        })

                        console.log(results.rows.item[r].Lat, results.rows.item(r).Lon)// i get both lat and long from the console log

                        loca[r] = (results.rows.item(r).lat)

                        loc[r] = (results.rows.item(r).Lon);

                        console.log(loc)

                        var gt = r.toString()

                        // pin[r] = (loc);

                        pina[r] = { text: gt }

                        pin[r] = new Microsoft.Maps.Pushpin(loca[r], loc[r]);

                        layer.add(pin[r])

                        console.log(pin[r])

                        var tj = (results.rows.item(r).Name)

                        var ty = (results.rows.item(r).Address)

                        var tp = (results.rows.item(r).Bait)

                        var te = (results.rows.item(r).Phone)

                        console.log(ty)

                        //  var pin = new Microsoft.Maps.Pushpin(lat2, lon2);

                        // map.layers.insert(layer)

                        map.layers.insert(layer)

                        // pin[r].Title = tj;

                        // pin[r].Description = "Address: " + ty + "<br\> Bait: " + tp + "<br\>Phone " + te + 'tags <a href="javascript:createDirections()">Directions. </a>'

                        // console.log(results.rows.item(r).Lat + " {" + results.rows.item(r).Lon + "}")

                        //       lat2 = results.rows.item(r).Lat

                        //   lon2 = results.rows.item(r).Lon

                        //        //                pinbox.Description = "refd, " + r

                        //  Microsoft.Maps.Events.addHandler(pin[r], 'click', displayInfobox);

                        //  map.entities.push(pin[r])

                    }

                }

            }

            

    thanks for all your help

    Ron

    Monday, July 4, 2016 12:26 PM
  • What do you mean by "html 1300", I've never heard of that term before.

    First off pull the cod for getting the users current position out of the array. Calling this multiple times in a loop is not needed and could cause issues on its own.

    Second verify that your Lat and Lon values are numbers and not a number string. If needed wrap with parseFloat.

    Third, and likely the main cause of your issue, pull the code to add the layer to map out side of the loop. You are adding it multiple times and this is likely causing issues.


    [Blog] [twitter] [LinkedIn]

    Tuesday, July 5, 2016 4:59 PM
  • Ricky thanks

     i have yet to get it working but i am still trying 

     i have done the parsefloat and they are numbers i think my problem is in the adding the layer i will work on this tonight thank you 

    i will mark as an answer soon but want to keep it open in case i  dont get it

    Ron 

    Saturday, July 9, 2016 3:46 PM
  • Ricky

    i am still having problems i think that i have the way i pass the gps wrong because i can get it with the test example but not with the gps

    does this look close?

     console.log(results.rows.item(r).Lat, results.rows.item(r).Lon)
                        loca[r] = parseFloat(results.rows.item(r).Lat)
                        loc[r] = parseFloat(results.rows.item(r).Lon);
                        


                   // var pushpins = Microsoft.Maps.TestDataGenerator.getPushpins(10, map.getBounds())
                     // var  locat= new Microsoft.Maps.Location(45.231658, -69.492536)
                      var pushpins =  new Microsoft.Maps.Pushpins(45.231658 , -69.492536);

                        console.log(loca[r], loc[r])

                        layer.add(pushpins)
                        
                            //Add a pushpin at the user's location.
                           
                         //   map.entities.push(pin);
                    }
                    map.layers.insert(layer)
                        

    • Marked as answer by Ronc1 Friday, July 15, 2016 11:54 PM
    • Unmarked as answer by Ronc1 Friday, July 15, 2016 11:57 PM
    • Marked as answer by Ronc1 Friday, July 15, 2016 11:58 PM
    Friday, July 15, 2016 2:17 AM
  • In the code above only one pushpin is created and added to the layer. However the pushpin is not created correctly. You need to create a Location object. For example

    var pushpins =  new Microsoft.Maps.Pushpins(new Microsoft.Maps.Location(45.231658, -69.492536));


    [Blog] [twitter] [LinkedIn]

    • Proposed as answer by Ricky_Brundritt Friday, July 15, 2016 3:14 PM
    • Marked as answer by Ronc1 Friday, July 15, 2016 11:58 PM
    Friday, July 15, 2016 3:14 PM
  • Ricky 

    thank you so much 

    Ron

    Friday, July 15, 2016 11:55 PM