0
votes

I have a small winform application that uses a WPF usercontrol to show a bing map on my winform. I can add a single pushpin, and set the location zoom etc,,

This is my xaml file :

<UserControl x:Class="MyBingWinForm.MyMapControl"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF">
<Grid>
    <m:Map Name="Map"/>
</Grid>

My C# file looks like this :

namespace MyBingWinForm
{
public partial class MyMapControl 
{
    public MyMapControl()
    {
        InitializeComponent();
        Map.Center = new Location(55.6760970, 12.5683370);

        Pushpin pin = new Pushpin();
        pin.Location = new Location(55.6760970, 12.5683370);
        Map.ZoomLevel = 12;
        // Adds the pushpin to the map.
        Map.Children.Add(pin);

        // Removes pushpin from the map.
        // myMap.Children.Remove(pin);
    }
}

}

I want to add multiple pushpins to the map, in some kind of iteration, thinking having a class with longitude and latitude or a sctruct, maybe an array.

Another wish is that the first pushpin in the list have a different look that the others but that is another question.

I hope some body can give me a small guide or lead me the right way. I am working in visual Studio 2012

1

1 Answers

0
votes

First figure u where you want to store your location data. You could store this in a local file, in a database (on a server or local), use the Bing Spatial Data services or some other storage system. Once you have the data stored somewhere you can then load it into your app. If you are using local files you might want to store the data using a standard spatial file format like GeoJSON, or KML. If you do this then you will need a tool to parse the data and load it on top of the WPF map. If you store the data in a database you will need to get the data to your app. If the database is local, then this is fairly easy. If it is on a server then you need to create a web service. In either approach you will likely find that Entity Framework really makes things easy. If you use the Bing Spatial Data Services you simply need to parse the REST response which is fairly easy to do. Once any of these are done you should end up with an array or list of objects that have some sort of location information in them. Simply loop through these objects and create pushpins and add them to the map or better yet a MapLayer.

Here are some useful resources:

http://mapstoolbox.codeplex.com/ - Provides tools to easily load spatial files into various Bing Maps controls, including WPF.

Here is info on creating a spatial webservice on top of a database:

https://blogs.bing.com/maps/2013/07/31/how-to-create-a-spatial-web-service-that-connects-a-database-to-bing-maps-using-ef5/

https://blogs.bing.com/maps/2013/08/05/advance-spatial-queries-using-entity-framework-5/

Here is documentation on the Bing Spatial Data Services:

https://msdn.microsoft.com/en-us/library/ff701734.aspx