My Wp7 (Mango) app needs to know the location of the user in order to search for the nearest object in the database. But I want to display the result on the welcome screen, so I need my location ASAP. I've written a code that starts the GeoCoordinateWatcher (on high precision and minimal threshold), and on the first firing it stops it, and sends the location to the webservice, which returns the object in question.

After I tested it, I went to present it, to the other side of the town. I started it and for everyone's amusement it showed a completely wrong result - I know why: it still thought I was at home!

How long does it take for the GPS to update? How will I know that I finally got my current location? How many times should I allow the GeoCoordinateWatcher to fire before stopping it?

有帮助吗?

解决方案

Check out the answer here:

http://awkwardcoder.blogspot.com/2011/09/geo-location-on-wp7-dont-trust-first.html

Basically, keep asking for updates until one is in the range from when you started requesting them.

in PositionChanged

if ( (DateTime.Now - e.Position.TimeStamp.DateTime) < LocationTimeout)
  {
         //recent enough.
  } 

其他提示

You have StatusChanged event for handling such as old user location (at home). When device status is ready - you have current location (but it can be inaccurate). So, use HorizontalAccuracy if you need high precision position ;)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top