1

是否可以获得我Map在 c# 中单击 bing 的位置的地理位置?

4

2 回答 2

1

好的,由于您在 C# 中使用 WinRT,因此您正在使用 Bing Maps Windows Store App 控件。将地图添加到 XAML 标记中:

<Page
    x:Class="Win8PublicApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:m="using:Bing.Maps">
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <m:Map Name="MyMap" Credentials="YOURKEY"/>
    </Grid>
</Page>

然后您可以执行此操作以在您单击的位置添加图钉:

public MainPage()
{
    this.InitializeComponent();

    this.MyMap.PointerPressedOverride += MyMap_PointerPressedOverride;
}

void MyMap_PointerPressedOverride(object sender, PointerRoutedEventArgs e)
{
    Bing.Maps.Location l = new Bing.Maps.Location();
    this.MyMap.TryPixelToLocation(e.GetCurrentPoint(this.MyMap).Position, out l);
    Bing.Maps.Pushpin pushpin = new Bing.Maps.Pushpin();
    pushpin.SetValue(Bing.Maps.MapLayer.PositionProperty, l);
    this.MyMap.Children.Add(pushpin);
}
于 2013-02-17T21:36:35.820 回答
-1

Bing Maps API 使这非常容易。

<!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"}); 

            //Add handler for the map click event.
            Microsoft.Maps.Events.addHandler(map, 'click', displayLatLong);


         }

          function displayLatLong(e) {
              if (e.targetType == "map") {
                  var point = new Microsoft.Maps.Point(e.getX(), e.getY());
                  var loc = e.target.tryPixelToLocation(point);
                  document.getElementById("textBox").value= loc.latitude + ", " + loc.longitude;

              }
          }

      </script>
   </head>
   <body onload="GetMap();">
      <div id='myMap' style="position:relative; width:400px; height:400px;"></div><br>
      <b>Click the map to display the coordinate values at that point.</b><br>
      Latitude, Longitude:       
      <input id='textBox' type="text" style="width:250px;"/>
   </body>
</html>

来源:MSDN 上的必应地图 API

于 2013-02-15T17:35:10.897 回答