模拟我当前的位置
如何像 GPS 一样在应用程序中模拟我的位置? 我想从附加工具 -> 中执行此操作 位置示例:
在模拟器上使用的
private void button2_Click(object sender, RoutedEventArgs e)
{
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
// You can specify a label and a geocoordinate for the end point.
// GeoCoordinate spaceNeedleLocation = new GeoCoordinate(47.6204,-122.3493);
// LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", spaceNeedleLocation);
// If you set the geocoordinate parameter to null, the label parameter is used as a search term.
LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", null);
bingMapsDirectionsTask.End = spaceNeedleLML;
// If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.
bingMapsDirectionsTask.Show();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一个
GeoCooperativeWatcher
监听 GPS 位置。稍后,当获取第一个位置时,您可以使用事件参数给定的坐标初始化LabeledMapLocation
并启动地图任务。示例:(
首先,将
System.Device
添加到项目的引用中。)在模拟器中,您可以在 Bing 地图上单击以根据需要更改当前位置。
您还应该注册
watcher.StatusChanged
。例如,此事件会告诉您 GPS 何时不可用。You need a
GeoCoordinateWatcher
to listen for GPS positions. Later, when getting the first position, you initialize theLabeledMapLocation
with the coordinates given by the event arguments and start the map task.Example:
(First, add
System.Device
to your project`s references.)And in the emulator you can click around on the Bing map to change your current position as you like.
You should also register for
watcher.StatusChanged
. This event tells you for example when GPS becomes unavailable.GeoCoordinateWatcher 是用于跟踪用户位置的正确类。如果您想模拟用户移动以进行测试,您可以使用 Mango 模拟器中的新位置跟踪功能。这是一篇很棒的文章:
http://www.jeffblankenburg.com/2011/11/01/31-days-of-mango-day-1-the-new-windows-phone-emulator-tools/
如果您想在运行时伪造用户位置,您只需创建 GeoCooperative 类的新实例并提供您想要的纬度、经度、海拔等任何值。
GeoCoordinateWatcher is the correct class for tracking the users location. If you want to simulate the user moving around for testing purposes you can use the new location tracking features in the Mango emulator. Here's a great article:
http://www.jeffblankenburg.com/2011/11/01/31-days-of-mango-day-1-the-new-windows-phone-emulator-tools/
If you are wanting to fake the users location at runtime, you can just create a new instance of the GeoCoordinate class and provide whatever values you want for Latitude, Longitude, Altitude, etc.