Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Phone 7 GetDistanceTo() returns incorrect distance
    text
    copied!<p>I am developing a small Windows Phone application. I am storing the current location of user in the database.</p> <p>Here is the code to retrieve the current location which is stored in database.</p> <pre><code>public void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs&lt;GeoCoordinate&gt; e) { CurrentLatitude = e.Position.Location.Latitude.ToString(); CurrentLongitude = e.Position.Location.Longitude.ToString(); } </code></pre> <p>We need to allow user to do some activity if he is under the 400 meters from his saved location. </p> <p>I am using the following code to calculate the distance.</p> <pre><code>internal double GetDistanceTo(GeoCoordinate ClientLocation) { double distanceInMeter; GeoCoordinate currentLocation = new GeoCoordinate(Convert.ToDouble(watcher.Position.Location.Latitude.ToString()), Convert.ToDouble(watcher.Position.Location.Longitude.ToString())); distanceInMeter = currentLocation.GetDistanceTo(ClientLocation); return distanceInMeter; } </code></pre> <p>ClientLocation : is the location saved in the database.</p> <p>So my problem is that it gives extremly large distance even the user is standing at the same location(under 1 meter) which is saved in the database.</p> <p>Example cordinates (extracted from device) </p> <p>Saved in Database </p> <blockquote> <p>Lat : 29.8752546310425<br> Long: 73.8865985870361</p> </blockquote> <p>Current Cordinates</p> <blockquote> <p>Lat : 29.8734102249146<br> Long :73.9049253463745</p> <p>Distance 1780.45</p> </blockquote> <p>Could anybody suggest me what is wrong here or a better way to get the distance between two coordinates?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload