문제

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