This sample demonstrates how to use the ArcGIS Runtime SDK for WPF to leverage the Microsoft Location API
and the GpsLayer to show your location on a map.
Note: This sample
requires Microsoft .Net 4.0 or higher on the Windows 7 operating
system and a location provider, such as a GPS device. For more
information please see
http://msdn.microsoft.com/en-us/library/windows/desktop/dd317661(v=VS.85).aspx
and http://msdn.microsoft.com/en-us/library/ee426011.aspx
using System;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Toolkit;
namespace ArcGISWPFSDK
{
///<summary>/// Interaction logic for GpsLayer.xaml///</summary>publicpartialclass SimpleGpsLayer : UserControl
{
//track the last reported point
ESRI.ArcGIS.Client.Geometry.MapPoint _lastPosition;
public SimpleGpsLayer()
{
InitializeComponent();
}
privatevoid GpsLayer_PositionChanged(object sender, EventArgs e)
{
if (_gpsLayer.Position != _lastPosition)
{
//Zoom the map to the current GPS position
_lastPosition = _gpsLayer.Position;
_mapControl.ZoomTo(new ESRI.ArcGIS.Client.Geometry.Envelope(
_gpsLayer.Position.X - 1000,
_gpsLayer.Position.Y - 1000,
_gpsLayer.Position.X + 1000,
_gpsLayer.Position.Y + 1000));
}
}
}
}
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client.Geometry
''' <summary>''' Interaction logic for GpsLayer.xaml''' </summary>Namespace ArcGISWPFSDK
PartialPublicClass SimpleGpsLayer
Inherits UserControl
'track the last reported pointPrivate _lastPosition As MapPoint
PublicSubNew()
InitializeComponent()
EndSubPrivateSub GpsLayer_PositionChanged(sender AsObject, e As EventArgs)
If _gpsLayer.Position IsNot _lastPosition Then'Zoom the map to the current GPS position
_lastPosition = _gpsLayer.Position
_mapControl.ZoomTo(New Envelope(_gpsLayer.Position.X - 1000, _gpsLayer.Position.Y - 1000, _gpsLayer.Position.X + 1000, _gpsLayer.Position.Y + 1000))
EndIfEndSubEndClassEndNamespace