在c#中查找位置bing map

时间:2014-01-18 13:25:53

标签: c# visual-studio-2010 windows-phone-7 bing-maps bing

我正在使用可视电话sdk编写一个Windows Phone应用程序,它给出了输入地址的位置。我能够做到(看下面的代码),但它总是重定向到下一页的bing地图。但我想在同一页面添加地图和文本字段。我将在文本字段中输入位置,地图将显示位置(使用visual studio的bing map)。有一些很好的例子我也可以参考。这将是一个很大的帮助。

namespace PhoneApp3
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        BingMapsTask bmt = new BingMapsTask();
        GeoCoordinateWatcher gcw = new GeoCoordinateWatcher();
        public MainPage()
        {
            InitializeComponent();
            map1.CredentialsProvider = new ApplicationIdCredentialsProvider("Your API Key");
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            GeoCoordinate gc = new GeoCoordinate(47,-127);
            bmt.Center = gc;

            bmt.ZoomLevel = 9;

            LocationRect.CreateLocationRect(gc);

            bmt.Show();

            //gcw.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(gcw_PositionChanged);
            //gcw.Start();
        }

        void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            textBox1.Text = e.Position.Location.Latitude.ToString();
            textBox2.Text = e.Position.Location.Longitude.ToString();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
            GeoCoordinate gc1 = new GeoCoordinate(47,-126);
            GeoCoordinate gc2 = new GeoCoordinate(47, -127);
            //LabeledMapLocation lml = new LabeledMapLocation("IIT Powai",)
            LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("",gc1);
            LabeledMapLocation spaceNeedleLML2 = new LabeledMapLocation("",gc2);
            bingMapsDirectionsTask.End = spaceNeedleLML;
            bingMapsDirectionsTask.Start = spaceNeedleLML2;
            // If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.

            bingMapsDirectionsTask.Show();
        }

    }
}

1 个答案:

答案 0 :(得分:0)

BingMapsTask旨在启动Bing Maps应用程序,如下所示:http://msdn.microsoft.com/en-us/library/windowsphone/develop/microsoft.phone.tasks.bingmapstask(v=vs.105).aspx

如果我正确理解您的要求,您希望将地图添加到您的应用程序和地理位置位置,并在地图上显示它们而无需离开您的应用。为此,您需要向应用程序添加一个地图,如下所示:http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207045(v=vs.105).aspx

然后,您可以使用GeocodeQuery对查询进行地理编码,如下所示:http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj244363(v=vs.105).aspx