Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Pushpin Class

Bing

Defines a pushpin on the map.

Constructor

Name Definition Description

Pushpin

Pushpin(location: Location , options?: PushpinOptions )

Initializes a new instance of the Pushpin class.

Methods

Name Definition Return Value Description

getAnchor

getAnchor()

Point

Returns the point on the pushpin icon which is anchored to the pushpin location. An anchor of (0,0) is the top left corner of the icon.

getIcon

getIcon()

string

Returns the pushpin icon.

getHeight

getHeight()

number

Returns the height of the pushpin, which is the height of the pushpin icon.

getLocation

getLocation()

Location

Returns the location of the pushpin.

getText

getText()

string

Returns the text associated with the pushpin.

getTextOffset

getTextOffset()

Point

Returns the amount the text is shifted from the pushpin icon.

getTypeName

getTypeName()

string

Returns the type of the pushpin.

getVisible

getVisible()

boolean

Returns whether the pushpin is visible. A value of false indicates that the pushpin is hidden, although it is still an entity on the map.

getWidth

getWidth()

number

Returns the width of the pushpin, which is the width of the pushpin icon.

getZIndex

getZIndex()

number

Returns the z-index of the pushpin with respect to other items on the map.

setLocation

setLocation(location: Location )

None

Sets the location of the pushpin.

setOptions

setOptions(options: PushpinOptions )

None

Sets options for the pushpin.

toString

toString()

string

Converts the Pushpin object to a string.

Events

Name Arguments Description

click

eventArgs:MouseEventArgs

Occurs when the mouse is used to click the pushpin.

dblclick

eventArgs:MouseEventArgs

Occurs when the mouse is used to double click the pushpin.

drag

object: {entity:Pushpin}

Occurs when the pushpin is being dragged.

dragend

eventArgs:MouseEventArgs

Occurs when the pushpin stops being dragged.

dragstart

eventArgs:MouseEventArgs

Occurs when the pushpin starts being dragged.

entitychanged

object: {entity:Entity}

Occurs when the location of the pushpin or any of the pushpin’s options change.

mousedown

eventArgs:MouseEventArgs

Occurs when the left mouse button is pressed when the mouse is over the pushpin.

mouseout

eventArgs:MouseEventArgs

Occurs when the mouse cursor moves out of the area covered by the pushpin.

mouseover

eventArgs:MouseEventArgs

Occurs when the mouse is over the pushpin.

mouseup

eventArgs:MouseEventArgs

Occurs when the left mouse button is lifted up when the mouse is over the pushpin.

rightclick

eventArgs:MouseEventArgs

Occurs when the right mouse button is used to click the pushpin.

Example

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "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 type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

      <script type="text/javascript">

         var map = null;         

         function GetMap()
         {
            // Initialize the map
            map = new Microsoft.Maps.Map(document.getElementById("myMap"),
                         {credentials:"Bing Maps Key"}); 

            // Retrieve the location of the map center 
            var center = map.getCenter();
            
            // Add a pin to the center of the map
            var pin = new Microsoft.Maps.Pushpin(center, {draggable: true}); 

            // Add a handler to the pushpin drag
            Microsoft.Maps.Events.addHandler(pin, 'mouseup', DisplayLoc);

            map.entities.push(pin);
         }

         function DisplayLoc(e){
            if (e.targetType == 'pushpin'){

               var pinLoc = e.target.getLocation();
               alert("The location of the pushpin is now " + pinLoc.latitude + ", " + pinLoc.longitude);

            }
}

      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div>
      <b>Drag the pushpin to a new location.</b>       
   </body>
</html>
Show:
© 2015 Microsoft