On my windows store app, im using a bings maps, and im trying to add a pushpin with an image to do so , im doing this piece of code

            Bing.Maps.Location center = new Bing.Maps.Location();
        center.Latitude = 40.130066068147585;
        center.Longitude = -8.338623046875;
        Map.Center = center;
        Map.ZoomLevel = 12D;

        var pushpinLayer = new MapLayer();
        pushpinLayer.Name = "PushPinLayer";
        Map.Children.Add(pushpinLayer);

        var location = new Location(40.130066068147585D, -8.338623046875D);
        Image pinImage = new Image();
        BitmapImage bitmapImage = new BitmapImage();
        bitmapImage.UriSource = new Uri("ms-appx:///Assets/POI_Red_Ipad@2x.png", UriKind.RelativeOrAbsolute);
        pinImage.Width = 20;
        pinImage.Height = 30;
        pinImage.Source = bitmapImage;

        pushpinLayer.Children.Add(pinImage);

it adds the pushpin image but it appears on the top left corner of the map, i dont know how to set its position to use the localtion variable :\

有帮助吗?

解决方案

Ok so you just have things a little out of order. The first part is correct:

    Bing.Maps.Location center = new Bing.Maps.Location();
    center.Latitude = 40.130066068147585;
    center.Longitude = -8.338623046875;
    Map.Center = center;
    Map.ZoomLevel = 12D;

Next, instead of creating a maplayer you would instead create your pushpin image:

    Image pinImage = new Image();
    BitmapImage bitmapImage = new BitmapImage();
    bitmapImage.UriSource = new Uri("ms-appx:///Assets/POI_Red_Ipad@2x.png",   UriKind.RelativeOrAbsolute);
    pinImage.Width = 20;
    pinImage.Height = 30;
    pinImage.Source = bitmapImage;

Then you can create your location:

var location = new Location(40.130066068147585D, -8.338623046875D);

Here is where it is different. You do not need to create an instance of the MapLayer class, instead assign the element (image in your case) and location - then add it to to the map.

MapLayer.SetPosition(pinImage, location);
Map.Children.Add(pinImage);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top