OIsaac


Hello. I am working on a winform application that uses VE. The Map shows the location absed on user input. My problem is that I am unable to show a marker on the map. Only the location shows. How would I go about placing a market at the target location


Re: Setting a marker at a target location entered by user

Derek Chan


Hi,

Since the location shows up by default on the center of the map, you could add a pushpin (marker) right into the centroid in your map.Find callback function.

Code Snippet
map.AddPushpin(map.GetCenter());


You'll likely want to add a customized pushpin/shape on that location so you'll need to tweak this to your needs.

Sample code that duplicates this:

Code Snippet

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
'>http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
; <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"></script>
<script>
var map = null;

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

function Find()
{
document.getElementById('resultDiv').innerHTML= "";

var what = document.getElementById('txtWhat').value;
var where = document.getElementById('txtWhere').value;

map.Find(what, where, null, null, null, null, null, null, null, null, callback);
}

function callback(a,b,c,d,e)
{

if (c != null && c.length > 1)
{
var results="More than one location was retruned. Please select the location you were looking for:<br>";
for (x=0; x<c.length; x++)
{
results+="<a href='javascript:map.Find(null, \""+c[x].Name+"\");'>"+c[x].Name+"</a><br>";
}
document.getElementById('resultDiv').innerHTML=results;
}
else
{
map.AddPushpin(map.GetCenter());
}
}
</script>
</head>
<body onload="GetMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
<div id='resultDiv' style="position:relative; width:400px;"></div>
<div>What:<input id="txtWhat" type="text" /></div>
<div>Where:<input id="txtWhere" type="text" /></div>
<div><input id="find" type="button" value="Find" name="find" onclick="Find();" /></div>
</body>
</html>


Hope that helps,







Re: Setting a marker at a target location entered by user

OIsaac

Thanks.