How to add push pin on map with mouse click using bing API RRS feed

  • Question

  • 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..

    My piece of code :

    <script charset="UTF-8" type="text/javascript" src=""></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 =;
               var location = new Microsoft.Maps.Location(locTemp.latitude, locTemp.longitude);
               var pin = new Microsoft.Maps.Pushpin(location, {'draggable': false});

    When I tried the above code, I am getting this error "Uncaught TypeError: Cannot call method 'push' of undefined ".

    Any help would be greatly appreciated.

    • Edited by Arun434 Monday, July 8, 2013 5:56 AM
    Monday, July 8, 2013 5:55 AM


  • Hi,

    you have a typo in your code. Should be:


    hope that helps,

    Viktor Halitsyn

    • Proposed as answer by Viktor Halitsyn Tuesday, July 9, 2013 12:32 AM
    • Marked as answer by Arun434 Wednesday, July 10, 2013 5:33 AM
    Tuesday, July 9, 2013 12:31 AM