我正在嘗試創建坐標數量不確定的地理圍欄,但 C# 和 Xamarin Forms Maps 不接受動態加載的內容。我已經確保總是有三個或更多的位置來創建地理圍欄。我試過這個,coordinates作為一個字串陣列:
Polygon geofence = new Polygon
{
StrokeColor = Color.Green,
FillColor = Color.Green,
Geopath =
{
foreach (string coordinate in coordinates)
{
string[] LongAndLat = coordinate.Split(',');
new Position(Convert.ToDouble(LongAndLat[0]), Convert.ToDouble(LongAndLat[1]));
}
}
};
這基本上告訴我 C# 不期望 Geopath 引數中的函式,但我不知道如何在不這樣做的情況下到達我想要的位置。
有沒有辦法正確地做到這一點?
uj5u.com熱心網友回復:
C# 語法無效。由于 Geopath 屬性是只讀的,您必須稍后分配該屬性。此解決方案有效:
string[] coordinates = geodata.Split(';');
Polygon geofence = new Polygon
{
StrokeColor = Color.Green,
FillColor = Color.FromRgba(0, 255, 0, 0.4)
};
foreach(string coordinate in coordinates)
{
string[] LongAndLat = coordinate.Split(',');
geofence.Geopath.Add(new Position(Convert.ToDouble(LongAndLat[0]), Convert.ToDouble(LongAndLat[1])));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/370560.html
標籤:C# 谷歌地图 xamarin.forms 多边形
上一篇:LaravelZOHOSMTP電子郵件無法通過身份驗證
下一篇:如何運行惰性評估?
