我无法让GPS工作

时间:2011-07-15 07:36:35

标签: windows-phone-7 geolocation gps

我正在使用此页面中的类来获取Windows Phone上的当前位置坐标:http://www.codeproject.com/Articles/134982/A-helper-class-to-get-the-current-location-on-a-Wi

我不知道为什么我总是得到“未知”的位置。我尝试过更简单的方法来获取位置,但没有成功。 我的GPS工作正常,因为我可以使用地图appand walk,我可以看到该点正确移动。 我检查了GeoCoordinateWatcher.Permisson属性,其值为“Granted”。我已在WMAppManifest.xml中使用此行<Capability Name="ID_CAP_LOCATION"/>

我不明白我上面给出的地址中的代码是这样的:

var immediate = new ImmediateLocation(x => location = x);
immediate.GetLocation();

GeoCoordinate location;

为什么在使用后声明位置?我之前宣布过。有什么我应该知道的吗?

[编辑]

现在我已经理解了lambda表达式我有两个例外:

A first chance exception of type 'System.NullReferenceException' occurred in System.Device.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

这是StackTrace

en System.Device.Location.GeoCoordinateWatcher.<>c__DisplayClass6.<OnPositionStatusChanged>b__4(Object _)
en System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
en System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
en System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
en System.Delegate.DynamicInvokeOne(Object[] args)
en System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
en System.Delegate.DynamicInvoke(Object[] args)
en System.Windows.Threading.DispatcherOperation.Invoke()
en System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
en System.Windows.Threading.Dispatcher.OnInvoke(Object context)
en System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
en System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
en System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

我发现了这一点,我不确定这与我的情况有关,但是如果有人帮助我......

http://onebusawaywp7.codeplex.com/workitem/14695

1 个答案:

答案 0 :(得分:0)

您为ImmediateLocation构造函数提供Action参数。去学习一些关于lambda表达式的东西 - 然后你会看到在声明它之前没有使用该位置。

就“未知”位置而言,在没有了解ImmediateLocation类的情况下,没有人可以回答。例如,取一个已发布的here:在调用GetLocation之后,该位置将异步填充,即有时在将来。如果你立即测试该值,那么你必须失败。在我看来,课程设计错误。

相关问题