locked
Problem with Pushpin and Longitude in v5 RRS feed

  • Question

  • VE v5 returns a JavaScript error when passing Longitude as a variable. Everything works fine when I pass in a scalar value (-111.717076). Here is my code:

     

    <!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>Untitled Page</title>

    <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5"></script>

    <script type="text/javascript">

    var map = null;

    var layer = null;

     

    function GetMap()

    {

    var xLat = document.getElementById('txtLat');

    var xLng = document.getElementById('txtLong');

     

    map = new VEMap('myMap');

    map.LoadMap(new VELatLong(xLat.value, xLng.value), 16, 'r', false);

     

    CreateLayer();

    //Add a pushpin to the new layer

    // This fails

    shape = new VEShape(VEShapeType.Pushpin, new VELatLong(xLat.value, xLng.value));

     

    // This works OK

    //shape = new VEShape(VEShapeType.Pushpin, new VELatLong(xLat.value, -111.717076));

     

    shape.SetTitle('My pushpin');

    shape.SetDescription('This is a pushpin.');

    shape.SetCustomIcon("<img src='Images/icoHouse.gif' />");

    layer.AddShape(shape);

    }

     

    function CreateLayer()

    {

    layer = new VEShapeLayer();

    map.AddShapeLayer(layer);

    }

    </script>

    </head>

    <body onload="GetMap();">

    <div id="myMap" style="position:relative; height: 254px; width: 600px;" />

    <div style="display: none;">

    <input id="txtLat" name="tLat" type="text" value="33.371076" />

    <input id="txtLong" name="tLong" type="text" value="-111.717076" />

    </div>

    </body>

    </html>

     

    Anybody had similar problem?

    Monday, May 14, 2007 5:15 AM

Answers

  • Agreed -- looks like a bug in the VEShape constructor code with the code path(s) it takes in validating the longitude value (continuing with the example above, this works, if only for the order of operations and implicit conversions)

     

    shape = new VEShape(VEShapeType.Pushpin, new VELatLong(xLat.value, -(-xLng.value)));

    Tuesday, May 15, 2007 1:17 AM

All replies

  • Hello

     

    this code works fine, once you correct the simple javascript error of a missing "}" at the end of the GetMap function :-)

     

    Let us know if you have any more issues after that.

     

    Brian Norman

    www.earthware.co.uk

     

    Monday, May 14, 2007 7:39 AM
    Moderator
  • Sorry, it was a typo. Anyway, it doesn't work. Pushpin has not been added to the shape/map.

    Any clues?

    Thank you.

    Monday, May 14, 2007 10:47 PM
  • I haven't tried your code, but I had a similar problem in v5 when the lat/long I was passing in were strings and not floats. It's easy to do typeof(var) and, if it's a string, use parseFloat to convert it to float.
    Monday, May 14, 2007 11:41 PM
  • Agreed -- looks like a bug in the VEShape constructor code with the code path(s) it takes in validating the longitude value (continuing with the example above, this works, if only for the order of operations and implicit conversions)

     

    shape = new VEShape(VEShapeType.Pushpin, new VELatLong(xLat.value, -(-xLng.value)));

    Tuesday, May 15, 2007 1:17 AM
  • That worked. Thanks guys!
    Tuesday, May 15, 2007 4:06 AM