Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 模拟我当前的位置_C#_Silverlight_Windows Phone 7_Bing - Fatal编程技术网

C# 模拟我当前的位置

C# 模拟我当前的位置,c#,silverlight,windows-phone-7,bing,C#,Silverlight,Windows Phone 7,Bing,如何像GPS一样在我的应用程序中模拟我的位置? 我想从其他工具->位置执行此操作 要在模拟器上使用的示例: private void button2_Click(object sender, RoutedEventArgs e) { BingMapsDirectionsTask bingMapsDirectionsTask = new BingMapsDirectionsTask(); // You can specify a label and a geocoordinate f

如何像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();
}
你需要一个耳机来监听GPS位置。稍后,在获取第一个位置时,使用事件参数给定的坐标初始化
LabeledMapLocation
,并启动映射任务

例如:

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

geocordinatewatcher-watcher;
//这将接收当前GPS位置(或模拟器中的模拟位置)
私有void handlegePositionChanged(对象发送方,地理位置变更数据源)
{
//我们只需要一个坐标-停止观察
watcher.Stop();
//初始化任务和位置
BingMapsDirectionsTask BingMapsDirectionsTask=新BingMapsDirectionsTask();
地理坐标SpaceNeedLocation=新的地理坐标(e.Position.Location.Latitude,e.Position.Location.Longitude);
LabeledMapLocation SpaceNeedlML=新的LabeledMapLocation(“空间针”,SpaceNeedLocation);
bingMapsDirectionsTask.End=spaceNeedleLML;
//如果未设置bingMapsDirectionsTask.Start,则将用户的当前位置用作起点。
bingMapsDirectionsTask.Show();
}
//这将开始监视GPS坐标,稍后将调用Bing任务
//当我们收到第一个坐标时
私有无效按钮1\u单击(对象发送者,路由目标)
{
//准备配合观察
watcher=newgeocordinatewatcher(GeoPositionAccuracy.Default){MovementThreshold=10};
//换岗登记
watcher.PositionChanged+=手柄位置已更改;
//开始看
watcher.Start();
}
在emulator中,你可以在Bing地图上随意点击来改变你当前的位置


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

GeoCoordinateWatcher是跟踪用户位置的正确类。如果您想模拟用户四处移动以进行测试,可以使用Mango emulator中的新位置跟踪功能。这里有一篇很棒的文章:


如果您想在运行时伪造用户位置,只需创建GeoCoordinate类的新实例,并提供您想要的纬度、经度、海拔高度等值。

以前没有听说过“Bing Phone 7;”
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();
}