gpt4 book ai didi

c# - 模拟我现在的位置

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:48 26 4
gpt4 key购买 nike

如何像 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();
}

最佳答案

你需要一个 GeoCoordinateWatcher收听 GPS 位置。稍后,当获得第一个位置时,您使用事件参数给定的坐标初始化 LabeledMapLocation 并启动 map task 。

例子:

(首先,将 System.Device 添加到项目的引用中。)

GeoCoordinateWatcher watcher;

// this receives the current GPS position (or the simulated one in the emulator)
private void HandleGeoPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
// we only need one coordinate - stop watching
watcher.Stop();

// initialize task and location
BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask();
GeoCoordinate spaceNeedleLocation = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
LabeledMapLocation spaceNeedleLML = new LabeledMapLocation("Space Needle", spaceNeedleLocation);
bingMapsDirectionsTask.End = spaceNeedleLML;

// If bingMapsDirectionsTask.Start is not set, the user's current location is used as the start point.

bingMapsDirectionsTask.Show();
}

// this starts watching for GPS coordinates, the Bing task will be invoked later
// when we receive our first coordinate
private void button1_Click(object sender, RoutedEventArgs e)
{
// prepare for coordinate watching
watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default) { MovementThreshold = 10 };
// register for position changes
watcher.PositionChanged += HandleGeoPositionChanged;
// start watching
watcher.Start();
}

并且在模拟器中,您可以在 Bing map 上四处单击以根据需要更改当前位置。

您还应该注册 watcher.StatusChanged。例如,此事件会告诉您 GPS 何时不可用。

关于c# - 模拟我现在的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8207327/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com