Wrong coordinate points bing maps

407 views Asked by At

I trying to cut the map to many rectangle parts and show ellipse in center like this:

demo

But the result is this:

Screenshot 1 Screenshot 2

XAML:

<Maps:MapControl x:Name="BingMap" Loaded="BingMap_Loaded">
    <Maps:MapItemsControl x:Name="MapPins">
        <Maps:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <Grid>
                    <Ellipse Fill="Red" Width="20" Height="20"></Ellipse>
                    <TextBlock Maps:MapControl.Location="{Binding Point}" Text="{Binding Count}" FontSize="20" Margin="5"/>
                </Grid>
            </DataTemplate>
        </Maps:MapItemsControl.ItemTemplate>
    </Maps:MapItemsControl>
</Maps:MapControl>

C#:

public async Task<List<Location>> ClusterCenters(double x)
{
    List<Location> locations = new List<Location>();

    for (double i = -85; i <= 85; i+=x)
    {
        for (double j = -170; j <= 170; j+=x*2)
        {
            locations.Add(new Location()
            {
                Count = 1,
                Title = String.Format("{0},{1}", i, j),
                Point = new Geopoint(new BasicGeoposition() {
                    Latitude = i,
                    Longitude = j
                })
            });
        }
    }

    return locations;
}

private async void BingMap_Loaded(object sender, RoutedEventArgs e)
{
    MapPins.ItemsSource = await ClusterCenters(10);
}
1

There are 1 answers

0
Antti Leppänen On BEST ANSWER

You have to remember that earth isn't flat :) Maps use always some projection to draw earth to 2D map. Because of this your points don't seem to be in right places.

Bing maps uses Mercator projection. You can find more information about Bings mapping system from here. There is sample code to calculate from screen coordinates to latitude and longitude(PixelXYToLatLong function).