【问题标题】:Set position of pushpin - BingMaps设置图钉的位置 - Bing 地图
【发布时间】:2014-02-06 17:19:16
【问题描述】:

在我的 Windows 商店应用程序中,我正在使用 bings 地图,并且正在尝试添加带有图像的图钉 为此,我正在做这段代码

            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);

它添加了图钉图像,但它出现在地图的左上角,我不知道如何设置它的位置以使用 localtion 变量:\

【问题讨论】:

    标签: c# xaml windows-store-apps bing-maps


    【解决方案1】:

    好吧,你只是有些事情有点乱。第一部分是正确的:

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

    接下来,您将创建图钉图像,而不是创建地图播放器:

        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;
    

    然后你可以创建你的位置:

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

    这是不同的地方。您无需创建 MapLayer 类的实例,而是分配元素(在您的情况下为图像)和位置 - 然后将其添加到地图中。

    MapLayer.SetPosition(pinImage, location);
    Map.Children.Add(pinImage);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多