简体   繁体   English

WP8在地图上加载列表框的位置

[英]WP8 loading listbox locations on map

I'm new to wp8 application development I would like to know how to load the map locations with listbox places.. I have no idea on it so please help me to know how to do it.. thanks in advance.. 我是wp8应用程序开发的新手,我想知道如何使用列表框位置加载地图位置。.我对此一无所知,所以请帮助我知道如何操作..在此先感谢。

I have a listbox with the places loaded with its latitude and longitude and a MAP button a side.. when I click the MAP button I should display the listbox places into the map.. so please anyone help me to do this... 我有一个listbox ,上面装有经度和纬度的位置,旁边有一个MAP按钮。.当我单击MAP按钮时,我应该在MAP显示该列表框的位置..所以请任何人帮助我做到这一点...

This is a code to just add map to the page.. (code behind) 这是一个仅将地图添加到页面的代码。(后面的代码)

private void Map_Click(object sender, RoutedEventArgs e)
{
            Map MyMap = new Map();
            MyMap.Height = 392;
            MyMap.Width = 412;
            MyMap.Center = new System.Device.Location.GeoCoordinate(-25.235,133.611);

            MyMap.ZoomLevel = 2;
            MyMap.LandmarksEnabled = true;
            MyMap.PedestrianFeaturesEnabled = true;
            MyMap.ColorMode = MapColorMode.Dark;
            srch.Children.Add(MyMap);
}

Well I don't know how your listbox looks like so I just created a empty Pushpin for each location. 好吧,我不知道您的列表框是什么样子,所以我只为每个位置创建了一个空图钉。

Following Method loops through every row in your ListBox and calls the method to draw the pushpin 以下Method循环遍历ListBox中的每一行,并调用该方法以绘制图钉

private void ReadListBox()
{
    foreach (var location in YourListBox)
    {
        DrawLocationToMap(new GeoCoordinate(latitudeInListBox, longitudeInListBox));
    }
}

Following method creates the location pushpin and adds it to your map 以下方法创建位置图钉并将其添加到地图

private void DrawLocationToMap(GeoCoordinate currGeo)
{
    Pushpin locationPushPin = new Pushpin();
    locationPushPin.Background = new SolidColorBrush(Colors.Black);

    MapOverlay locationPushPinOverlay = new MapOverlay();
    locationPushPinOverlay.Content = locationPushPin;
    locationPushPinOverlay.PositionOrigin = new Point(0.5, 0.5);
    locationPushPinOverlay.GeoCoordinate = new GeoCoordinate(currGeo.Latitude, currGeo.Longitude);

    MapLayer locationLayer = new MapLayer();
    locationLayer.Add(locationPushPinOverlay);

    MyMap.Layers.Add(locationLayer);
}

You'll need the WPToolkit to use PushPins. 您需要WPToolkit才能使用PushPins。 To install the toolkit you'll need NuGet . 要安装工具箱,您将需要NuGet How to install: http://docs.nuget.org/docs/start-here/installing-nuget 如何安装: http//docs.nuget.org/docs/start-here/installing-nuget

After NuGet is installed, open the console 安装NuGet之后,打开控制台 在此处输入图片说明

and enter 然后输入

Install-Package WPtoolkit 安装包WPtoolkit

Finally just add the namespace into your xaml 最后,只需将名称空间添加到您的xaml中

 xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM