Problem in Muliple PushPins
Hi,
I have problem in drawing multiple pushpins,
The problem is
I have DataView on the aspx page which contains address,
I have to put push pin on the map for each address in the DataView.
the following is the code to read all address in DataView and drawing pushpins for each address using javascript
function FindLoc()
{
var Address, i=0;
var gvAddress=document.getElementById('grvLoans');
for (var i=1;i<gvAddress.rows.length;i++)
{
var rowElem = gvAddress.rows
;
var status = rowElem.cells[4].innerHTML;
// Show pushpin if status is not empty
if (status !='')
{
add= rowElem.cells[3].innerHTML +", " + rowElem.cells[1].innerHTML +", " + rowElem.cells[2].innerHTML +" " + rowElem.cells[0].innerHTML;
showAddress(add, status)
}
}
returnfalse;
}
function showAddress(address, status)
{
try
{
var image;
image ='Images/pushpin_red.gif';
AddPin(image ,address, address,'');
}
catch(err)
{
window.alert("Unable to process the location");
}
}
function AddPin(image, where, _Title, _Description)
{
if(map.GetMapStyle() == VEMapStyle.Birdseye)
returnfalse;
icon = image
Title = _Title;
Description = _Description;
map.Find(null, where,null, layer,0,20,true,false,true,false,onFindResults);
}
function onFindResults(a,b,c,d,e)
{
alert(pinID);
var LatLon =new VELatLong(c[0].LatLong.Latitude, c[0].LatLong.Longitude);
var shape =new VEShape(VEShapeType.Pushpin, LatLon);
shape.SetTitle(Title);
shape.SetDescription(Description);
shape.SetCustomIcon(icon);
map.AddShape(shape);
pinID++;
map.PanToLatLong(LatLon);
}
The above code is to draw multiple pushpins but it is not working please check the code if there is any error.
it is drawing only one pushpin.
Thanks
DVR Prasad
Something like this should work:
var gIndex=0;
var gvAddress;
function FindLoc()
{
var Address;
gvAddress = document.getElementById('grvLoans');
gIndex = 0;
// just show the first address
// move the "show pushpin if status not empty" logic into showAddress
showAddress(gIndex);
return false;
}
function showAddress(gIndex)
{
var rowElem = gvAddress.rows[index];
var status = rowElem.cells[4].innerHTML;
// show pushpin if status not empty
if (status != '')
{
var address = rowElem.cells[3].innerHTML + ", " + rowElem.cells[1].innerHTML + ", " + rowElem.cells[2].innerHTML + " " + rowElem.cells[0].innerHTML;
try
{
var image;
image = Images/pushpin_red.gif';
AddPin(image, address, address, '');
}
catch(err)
{
window.alert("Unable to process the location");
}
}
}
function AddPin(image, where, _Title, _Description)
{
if(map.GetMapStyle() == VEMapStyle.Birdseye)
return false;
icon = image
Title = _Title;
Description = _Description;
map.Find(null, where, null, layer,0,20,true,false,true,false,onFindResults);
}
function onFindResults(a,b,c,d,e)
{
alert(pinID);
var LatLon = new (VELatLong(c[0].LatLong.Latitude, c[0].LatLong.Longitude);
var shape = new VEShape(VEShapeType.Pushpin, LatLon);
shape.SetTitle(Title);
shape.SetDescription(Description);
shape.SetCustomIcon(icon);
map.AddShape(shape);
pinID++;
map.PanToLatLong(LatLon);
// we just found one pin. Now, start the search for the next pin:
//
gIndex++;
if (gIndex < gvAddress.rows.length)
{
showAddress(gIndex);
}
}
If you call map.Find(null, myPlace, .... onFindResults), then immediately call map.Find(null, somewhereElse, ... onFindResults), I believe that the first "map.Find" may get lost. (Meaning, I think you can only have one "Find" running at once.) So, onFindResults will only get called for "somewhereElse"'s request, and never gets called for myPlace.
In my fixed code, FindLoc only requests one pushpin. Then, when that one has completed, onFindResults gets called. onFindResults then calls showAddress for the next address. When that one's finished, onFindResulsts gets called again, & it calls showAddress again.
Note: I'm not an expert on this, so my assumption about "Find" may be wrong. But I do know that I've seen multiple pushpins work before, using the algorithm mentioned above.
Good luck...
-Jason