Reputation: 7267
Here i am trying to get multiple pushpins on bing maps, so i have an array of latitude & longitude and i am passing those values from array to bing maps lat&lon variable.
When i use those variables to place pushpins on map, i can't see pushpins on map. How can i solve this?
here is what i have done
Code:
function showLoc()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: bkey});
map.setView({ zoom: 12, center: new Microsoft.Maps.Location(lat,lon) })
map.entities.clear();
var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), null);
map.entities.push(pushpin);
var index;
var latlon = ["12.978955,77.574838", "12.981472,77.619214", "12.980332,77.617265", "13.011561,77.606354", "12.975496,77.556826", "12.97518,77.570991", "12.971599,77.594563", "12.985405,77.525386"];
for (index = 0; index < latlon.length; index++) {
var laton = latlon[index];
pushpin.setLocation(new Microsoft.Maps.Location(laton));
}
}
Upvotes: 0
Views: 975
Reputation: 17954
You have to create a pushpin for each location, otherwise you just keep moving the same pushpin all over. You also have to parse your string values into coordinate parse (two numbers). Modify your code to something like this:
function showLoc()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: bkey});
map.setView({ zoom: 12, center: new Microsoft.Maps.Location(lat,lon) })
map.entities.clear();
var latlon = ["12.978955,77.574838", "12.981472,77.619214", "12.980332,77.617265", "13.011561,77.606354", "12.975496,77.556826", "12.97518,77.570991", "12.971599,77.594563", "12.985405,77.525386"];
for (var i = 0; i < latlon.length; i++) {
var vals = latlon[index].split(',');
if(vals.length >= 2){
var pushpin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(parseFloat(vals[0]), parseFloat(vals[1])));
map.entities.push(pushpin);
}
}
}
Upvotes: 2