Jeffz80


I wonder how to add multiple Pushpins based on addresses onLoad()

I code in following however I only get one pushpin instead of two. It seems that whereResults[0] in callback keep getting the first address only. I don't know why.

Code Snippet

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx v=5" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
var map = null;
var address = "";
var shape = null;
var defaultMap = true;

function GetMap()
{
map = new VEMap('myMap');
map.LoadMap();
map.HideDashboard();
}

function Find()
{
var what = null;
var where = address;
var findType = null;
var shapeLayer = null;
var startIndex = 0;
var numberOfResults = 10;
var showResult = true;
var createResult = true;
var disambiguation = true;
var setBestMapView = true;
try
{
map.Find(what, where, findType, shapeLayer, startIndex, numberOfResults, showResult, createResult, disambiguation, setBestMapView, callback);
}
catch(e)
{
alert(e.message);
}
}

function callback(layer, whatResults, whereResults, hasMore)
{
if(whereResults != null && !defaultMap)
{
shape = new VEShape(VEShapeType.Pushpin, whereResults[0].LatLong);
map.AddShape(shape);
//Set the info box
map.ClearInfoBoxStyles();
shape.SetTitle("Address:");
if (whereResults[0].Name!=null && whereResults[0].Name.length > 0)
{
shape.SetDescription(whereResults[0].Name);
}
else
{
shape.SetDescription(txtWhere.value);
}
}
}

function DeleteShape()
{
if(shape != null)
{
map.DeleteShape(shape);
shape = null
}
}

function AddPoints()
{

defaultMap = false;
address = '3500 north charles street, baltimore, md, 21210, ';
Find();

address = '4006 linkwood, md, 21210, ';
Find();
}

</script>
</head>
<body onload="GetMap();AddPoints();">

<div id='myMap' style="position:relative; width:100%; height:100%;"></div>

</body>
</html>

Thanks for helping




Re: How to add multiple Pushpins based on different address onLoad()?

Derrick


At the moment, you can only have a single request to Find at a time. That's why you're getting only 1 result. A workaround for this is to chain the request. In the callback of the first find, you can fire off the second find.

If you need help with this, I can modify your codes. However, if shouldn't be too difficult. Drop me a note if you need more help.






Re: How to add multiple Pushpins based on different address onLoad()?

Jeffz80

Thanks, Derrick. That helps, though first time I got infinitly loop .

Does SDK have this specified for single request I had hard time to find an explaination for callback with its parameters. If you looked my callback it contains 4 parameters. But from the source code page of official interactive sdk online, it has 5 parameters. I just wonder what's the fifth one.

Thanks again.






Re: How to add multiple Pushpins based on different address onLoad()?

Derrick

Currently, it's a string containing the error message, if there's 1. However, since it's not documented, don't count on it been supported in future release.