C# 在地图上显示gps位置
我在windows mobile应用程序中工作,我想用谷歌地图显示我的当前位置。我使用了示例中的位置dll。正如您在下面的代码中所看到的,我在gps\U Locationchanged事件中调用了更新地图的正确方法,在该事件中,我使用Invoke方法更新pictureboxe的图像。问题是我不能在任何时候使用应用程序的主菜单和上下文菜单。就好像他们在新地图下载完毕之前都会被冻结一样。有没有其他方法可以在不同的线程中实现这一点,以便随时使用C# 在地图上显示gps位置,c#,windows-mobile,C#,Windows Mobile,我在windows mobile应用程序中工作,我想用谷歌地图显示我的当前位置。我使用了示例中的位置dll。正如您在下面的代码中所看到的,我在gps\U Locationchanged事件中调用了更新地图的正确方法,在该事件中,我使用Invoke方法更新pictureboxe的图像。问题是我不能在任何时候使用应用程序的主菜单和上下文菜单。就好像他们在新地图下载完毕之前都会被冻结一样。有没有其他方法可以在不同的线程中实现这一点,以便随时使用 void gps_LocationChanged(obj
void gps_LocationChanged(object sender, LocationChangedEventArgs args)
{
if (args.Position.LatitudeValid && args.Position.LongitudeValid)
{
pictureBox1.Invoke((UpdateMap)delegate()
{
center.Latitude = args.Position.Latitude;
center.Longitude = args.Position.Longitude;
LatLongToPixel(center);
image_request2(args.Position.Latitude, args.Position.Longitude);
});
}
}
很难说清楚,但问题似乎在于(我假设)从服务器获取实际图像的image_request2()方法。如果您要在工作线程上运行此方法,并提供一个简单的回调方法,在图像完全下载后在屏幕上绘制图像,这将使您的UI线程保持打开状态,以接收来自用户的事件。可能是这样的
bool m_fetching;
void gps_LocationChanged(object sender, LocationChangedEventArgs args)
{
if (m_fetching) return;
if (args.Position.LatitudeValid && args.Position.LongitudeValid)
{
ThreadPool.QueueUserWorkItem(UpdateProc, args);
}
}
private void UpdateProc(object state)
{
m_fetching = true;
LocationChangedEventArgs args = (LocationChangedEventArgs)state;
try
{
// do this async
var image = image_request2(args.Position.Latitude, args.Position.Longitude);
// now that we have the image, do a synchronous call in the UI
pictureBox1.Invoke((UpdateMap)delegate()
{
center.Latitude = args.Position.Latitude;
center.Longitude = args.Position.Longitude;
LatLongToPixel(center);
image;
});
}
finally
{
m_fetching = false;
}
}