模拟我当前的位置 [英] Simulate my current position

查看:160
本文介绍了模拟我当前的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何模拟我的位置在我的应用程序,如GPS呢?
我想这样做在其他的工具 - >位置



例在模拟器使用方法:

 私人无效button2_Click(对象发件人,RoutedEventArgs E)
{
bingMapsDirectionsTask bingMapsDirectionsTask =新bingMapsDirectionsTask();

//您可以指定一个标签和结束点会有地理座标。
//会有地理座标spaceNeedleLocation =新会有地理座标(47.6204,-122.3493);
// LabeledMapLocation spaceNeedleLML =新LabeledMapLocation(太空针,spaceNeedleLocation);

//如果设置会有地理座标参数设置为null,标签参数被用作搜索词。
LabeledMapLocation spaceNeedleLML =新LabeledMapLocation(太空针,NULL);


bingMapsDirectionsTask.End = spaceNeedleLML;

//如果未设置bingMapsDirectionsTask.Start,用户的当前位置被用作起始点。

bingMapsDirectionsTask.Show();
}


解决方案

您需要的 GeoCoordinateWatcher 监听GPS位置。后来,得到的第一个位置的时候,你初始化 LabeledMapLocation 由事件参数给出,并开始map任务的坐标。



例如:



(。首先,添加 System.Device 您project`s参考)

  GeoCoordinateWatcher守望者; 

//这个接收当前GPS位置(或模拟一个在模拟器)
私人无效HandleGeoPositionChanged(对象发件人,GeoPositionChangedEventArgs<会有地理座标> E)
{
//我们只需要一个坐标 - 驻足观望
watcher.Stop();

//初始化任务和位置
BingMapsDirectionsTask bingMapsDirectionsTask =新BingMapsDirectionsTask();
会有地理座标spaceNeedleLocation =新会有地理座标(e.Position.Location.Latitude,e.Position.Location.Longitude);
LabeledMapLocation spaceNeedleLML =新LabeledMapLocation(太空针,spaceNeedleLocation);
bingMapsDirectionsTask.End = spaceNeedleLML;

//如果未设置bingMapsDirectionsTask.Start,用户的当前位置被用作起始点。

bingMapsDirectionsTask.Show();
}

//这个开始看的GPS坐标,Bing的任务将在稍后被调用时,我们收到我们的第一个坐标
私人无效的button1_Click(对象
//发件人,RoutedEventArgs E)
{
//准备协调看
观察家=新GeoCoordinateWatcher(GeoPositionAccuracy.Default){MovementThreshold = 10};
//于位置寄存器改变
watcher.PositionChanged + = HandleGeoPositionChanged;
//开始看
watcher.Start();
}

和在模拟器中,你可以点击周围的冰地图上更改当前只要你喜欢的位置。



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


How to simulate my position in my app like GPS does? I want to do this from Additional Tools -> Location

Example to use on your emulator:

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

解决方案

You need a GeoCoordinateWatcher to listen for GPS positions. Later, when getting the first position, you initialize the LabeledMapLocation with the coordinates given by the event arguments and start the map task.

Example:

(First, add System.Device to your project`s references.)

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

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.

这篇关于模拟我当前的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆