Sivya


Hi,

For virtual earth I tried to add PushPin with V4 as below and it worked

map.AddPushpin(new VEPushpin(ID, new VELatLong(lat, lng),

With V5 if I try
var pin = new VEShape(VEShapeType.Pushpin,new VELatLong(lat, lng));
map.AddShape(pin);

I am getting the error "Shape is not initialized" but if I use constant
value for lat, lng as below then everything works fine.

var pin = new VEShape(VEShapeType.Pushpin,new VELatLong(43.4444, -79.6666));
map.AddShape(pin);

lat,lng are Java Script Variables. I geocoded the location and saved the
Longitude/Latitude. Now I want to add PushPin for this Long/Lat

Thanks




Re: Error: Shape is not initialized

SoulSolutions


Just a guess but could your lat/long values be strings instead of numbers

try:

Code Block
new VELatLong(parseFloat(lat),parseFloat(lng))

John.







Re: Error: Shape is not initialized

Richard_Brundritt

This was a bug that was introduced when V5 came out. Luckily there has been a work around made. You where on the right path by using the the VEShape class but you were missing the square brackets around the VELatLong. Below is a sample program I put together that allows the users to input a value for latitude and longitude.

<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;
var pinID = 1;

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

function AddPin()
{
try
{
var latlong = new VELatLong(document.getElementById('lat').value,document.getElementById('long').value);
var shape = new VEShape( VEShapeType.Pushpin,[latlong]);
map.AddShape(shape);
}
catch(e)
{
alert(e.message);
}
}
</script>
</head>
<body onload="GetMap();">
<CENTER>
<div id='myMap' style="position:relative; width:600px; height:400px;"></div>
Lat: <INPUT id="lat" type="text" name="start" value="0"/>
Long: <INPUT id="long" type="text" name="end" value="0"/>
<INPUT id="addpin" type="button" value="Add Pin" name="addpin" onclick="AddPin();">
</CENTER>
</body>
</html>





Re: Error: Shape is not initialized

Sivya

That Worked!!. I was missing the bracket [latlong]);

Thank you for your help