【问题标题】:How to add map marker from lat/lng coordinates? Windows 8 phone如何从纬度/经度坐标添加地图标记? Windows 8 手机
【发布时间】:2014-02-18 23:53:46
【问题描述】:

我已经从工具箱向应用程序添加了一个地图,但我试图弄清楚如何向地图添加一个标记,该标记将由按钮的单击事件触发。我知道如何获取设备的当前位置,如下所示。

但是我将如何添加到此以使用此位置数据在地图上绘制图钉/标记?有没有一种简单的方法可以使用从这段代码 sn-p 计算的 lat/lng 添加标记?

Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;

try
{
    Geoposition geoposition = await geolocator.GetGeopositionAsync(
        maximumAge: TimeSpan.FromMinutes(5),
        timeout: TimeSpan.FromSeconds(10)
        );

    LatitudeTextBlock.Text = geoposition.Coordinate.Latitude.ToString("0.00");
    LongitudeTextBlock.Text = geoposition.Coordinate.Longitude.ToString("0.00");
}
catch (Exception ex)
{
    if ((uint)ex.HResult == 0x80004004)
    {
        // the application does not have the right capability or the location master switch is off
        StatusTextBlock.Text = "location  is disabled in phone settings.";
    }
    //else
    {
        // something else happened acquring the location
    }
}

【问题讨论】:

    标签: c# windows-phone-8 geolocation maps


    【解决方案1】:

    这比 Windows 8 多一点工作:

            var overlay = new MapOverlay { PositionOrigin = new Point(0.5, 0.5), GeoCoordinate = coordinate };
    
            var img = new Image { Width = 56, Height = 56 };
            img.Source = new BitmapImage { UriSource = new Uri("/Assets/Icons/pin.png", UriKind.Relative) };
            img.Tag = coordinate;
            img.Tap += delegate
            {
                // handle tap
            };
    
            overlay.Content = img;
    
            var mapLayer = new MapLayer { overlay };
            map.Layers.Add(mapLayer);
    

    【讨论】:

    • 酷,我如何将坐标从我的方法传递给这个?是在GeoCoordinate = coordinate 行,那么我如何将 lat 和 lng 传递给这段代码?
    • 如何将 lat/lng 坐标设置为坐标变量,因为它似乎只需要一个值?
    猜你喜欢
    • 2012-02-18
    • 2018-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    相关资源
    最近更新 更多