我想在Windows手机中的地理坐标上绘制离线圈 这个圆圈的范围是1500米,它在这个范围内搜索目标
这是我的图像,我指向使用宽度和高度绘制圆,但我想绘制圆 在缩放时使用半径,圆圈的范围也受影响
并且还搜索此范围内的目标
// double metersPerPixels = (Math.Cos(geo.Latitude * Math.PI / 180) * 2 * Math.PI * 6378137) / (256 * Math.Pow(2, map.ZoomLevel));
// double radius = 1000 / metersPerPixels;
map.Layers.Add(new MapLayer()
{
new MapOverlay()
{
GeoCoordinate = geo,
PositionOrigin = new Point(0.5,0.5),
Content = new Ellipse
{
Opacity=.4,
Fill = new SolidColorBrush(color),
Width = 100,//radius * 2
Height =100 //adius * 2
}
}
});
答案 0 :(得分:2)
在这里,您可以通过更改此帮助程序中的Location
类来将其用于您自己的类。
以下是从初始化点和半径以米为单位创建圆的样本助手:
/// <summary>
/// The geo drawing helper.
/// </summary>
public class GeoDrawingHelper
{
#region Constants
/// <summary>
/// The c_ earth radius in kilometers.
/// </summary>
public const double c_EarthRadiusInKilometers = 6367.0;
#endregion
#region Public Methods and Operators
/// <summary>
/// Creates a circle by the initializing point.
/// </summary>
/// <param name="center">
/// The center Point.
/// </param>
/// <param name="radius">
/// The radius in meter.
/// </param>
/// <returns>
/// The <see cref="List"/>.
/// </returns>
public static List<Location> CreateCirclePoints(Location center, double radius)
{
double lat = ToRadian(center.Latitude); // radians
double lng = ToRadian(center.Longitude); // radians
double d = radius / (c_EarthRadiusInKilometers * 1000); // d = angular distance covered on earth's surface
var locations = new List<Location>();
for (var x = 0; x <= 360; x++)
{
// Calculate the coordinates of the point
double brng = ToRadian(x);
double latRadians = Math.Asin((Math.Sin(lat) * Math.Cos(d)) + (Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng)));
double lngRadians = lng
+ Math.Atan2(
Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat),
Math.Cos(d) - (Math.Sin(lat) * Math.Sin(latRadians)));
// Add the location
locations.Add(new Location() { Latitude = ToDegrees(latRadians), Longitude = ToDegrees(lngRadians) });
}
return locations;
}
/// <summary>
/// Convert the radian to degrees measure.
/// </summary>
/// <param name="radians">
/// The radians.
/// </param>
/// <returns>
/// The <see cref="double"/>.
/// </returns>
public static double ToDegrees(double radians)
{
return radians * (180 / Math.PI);
}
/// <summary>
/// Convert the degrees to radian measure.
/// </summary>
/// <param name="degrees">
/// The degrees.
/// </param>
/// <returns>
/// The <see cref="double"/>.
/// </returns>
public static double ToRadian(double degrees)
{
return degrees * (Math.PI / 180);
}
#endregion
}
答案 1 :(得分:1)
为防止某些纬度上的省略号,我使用以下代码:
// Function to draw circle on map:
private void DrawCircle(BasicGeoposition CenterPosition, int Radius)
{
Color FillColor = Colors.Purple;
Color StrokeColor = Colors.Red;
FillColor.A = 80;
StrokeColor.A = 80;
Circle = new MapPolygon
{
StrokeThickness = 2,
FillColor = FillColor,
StrokeColor = StrokeColor,
Path = new Geopath(Functions.CalculateCircle(CenterPosition, Radius))
};
mpBingMaps.MapElements.Add(Circle);
}
// Constants and helper functions:
const double earthRadius = 6371000D;
const double Circumference = 2D * Math.PI * earthRadius;
public static List<BasicGeoposition> CalculateCircle(BasicGeoposition Position, double Radius)
{
List<BasicGeoposition> GeoPositions = new List<BasicGeoposition>();
for (int i = 0; i <= 360; i++)
{
double Bearing = ToRad(i);
double CircumferenceLatitudeCorrected = 2D * Math.PI * Math.Cos(ToRad(Position.Latitude)) * earthRadius;
double lat1 = Circumference / 360D * Position.Latitude;
double lon1 = CircumferenceLatitudeCorrected / 360D * Position.Longitude;
double lat2 = lat1 + Math.Sin(Bearing) * Radius;
double lon2 = lon1 + Math.Cos(Bearing) * Radius;
BasicGeoposition NewBasicPosition = new BasicGeoposition();
NewBasicPosition.Latitude = lat2 / (Circumference / 360D);
NewBasicPosition.Longitude = lon2 / (CircumferenceLatitudeCorrected / 360D);
GeoPositions.Add(NewBasicPosition);
}
return GeoPositions;
}
private static double ToRad(double degrees)
{
return degrees * (Math.PI / 180D);
}
此代码适用于小于半英里的小半径。