Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

DZone's Guide to

# Drawing Accuracy Circle in Bing Maps on WP7

· Mobile Zone
Free Resource

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

While developing a location-based application, I was experiencing strange problems with the GPS service accuracy. My location varied wildly all over the place and I needed a better way to visualize my location. Along with drawing a marker on the map indicating where I am, I also a wanted to draw a circle around it to see what is the accuracy threshold for it.

When GeoCoordinateWatcher sends a notification about a new position, you can retrieve the horizontal accuracy information via the GeoCoordinate.HorizontalAccuracy property. Since there is no circle or ellipse shape for map, you can approximate it with MapPolygon. I’ve declared it in the following way:

```<my:MapPolygon Fill="#99FF0000" Stroke="Red"
StrokeThickness="1"
Opacity="0.6"
x:Name="precision" />```

The code is adapted from Steve Strong’s blog post. The full code for drawing a circle:

```private void UpdatePrecision(GeoCoordinate location)
{
precision.Visibility = Visibility.Collapsed;
if (location == null)
return;

precision.Visibility = Visibility.Visible;
precision.Locations = new LocationCollection();

var lat = location.Latitude * Math.PI / 180.0; //radians
var lon = location.Longitude * Math.PI / 180.0; //radians
var d = location.HorizontalAccuracy / 1000 / earthRadius; // d = angular distance covered on earths surface

for (int x = 0; x <= 360; x++)
{
var brng = x * Math.PI / 180.0; //radians
var latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));
var lngRadians = lon + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), Math.Cos(d) - Math.Sin(lat) * Math.Sin(latRadians));

var pt = new GeoCoordinate(180.0 * latRadians / Math.PI, 180.0 * lngRadians / Math.PI);
}
}```

On the image below you can see it in action.

Since emulator is very “precise”, I had to zoom in a bit. In regular usage the accuracy will vary.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Published at DZone with permission of Toni Petrina, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

SEE AN EXAMPLE