[GIS] How to add push pin on map with mouse click using bing API

bing-maps

I am new to BING API. What my requirement is I have to add a pushpin on my map where the mouse is clicked.

I added a map to my web page, created an click event on map and try to add a push pin. But its not working..

Mu piece of code :

<script charset="UTF-8" type="text/javascript" src="https://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&s=1"></script>



    <script type="text/javascript">
    var map,mapoptions; 
    var pinInfobox = null;
    function init() 
    {

        var bingkey="Bing map key";

        var loc=new Microsoft.Maps.Location(58.995311, -103.535156)
        mapOptions ={   credentials: bingkey,
                        center: loc,
                        zoom: 3,
                        mapTypeId: Microsoft.Maps.MapTypeId.road
                }

        map = new Microsoft.Maps.Map(document.getElementById("bingMap"), mapOptions);
        Microsoft.Maps.Events.addHandler(map, 'click',getLatlng );          
    }
    function getLatlng(e) { 
        if (e.targetType == "map") {
           var point = new Microsoft.Maps.Point(e.getX(), e.getY());
           var locTemp = e.target.tryPixelToLocation(point);
           var location = new Microsoft.Maps.Location(locTemp.latitude, locTemp.longitude);
         alert(locTemp.latitude+"&"+locTemp.longitude);


           var pin = new Microsoft.Maps.Pushpin(location, {'draggable': false});

             map.entites.push(pin);
             alert("Done");

        }              
       }
      </script>

This is my script. This init() function is invoked on body onload.

Any help is greatly appreciated ..

Best Answer

There is an error in the code =>

map.entites.push(pin);

should be changed to:

map.entities.push(pin);