我有一个非常简单的代码和一些非常简单的文件。
我已经创建了一个C#文件来插入一些数据并从中收集引脚,但当我这样做时,它给我这个错误:
错误CS0246未能找到类型或命名空间名称"Places"(是否缺少using指令或程序集引用?)
- 我的密码:**
- 数据. cs**
using System;
using System.Collections.Generic;
using System.Text;
namespace Orbage
{
class DATA
{
string Label = "USA",
Address = "This is the US",
Lat = "40.060407",
Lng = "-102.453091";
}
}
- MapPage. cs**(* 此处为错误 *)
using System.Collections.Generic;
using Xamarin.Forms.Maps;
using Xamarin.Forms;
using System.IO;
using Newtonsoft.Json;
namespace Orbage
{
class MapPage : ContentPage
{
public MapPage()
{
CustomMap customMap = new CustomMap
{
MapType = MapType.Street
};
// ...
Content = customMap;
var json = File.ReadAllText("DATA");
var places = JsonConvert.DeserializeObject<List<Places>>(json);
foreach (var place in places)
{
CustomPin pin = new CustomPin
{
Type = PinType.Place,
Position = new Position(place.lat,place.lng),
Label = place.Label,
Address = place.Address,
Name = "Xamarin",
Url = "http://xamarin.com/about/"
};
customMap.CustomPins = new List<CustomPin> { pin };
customMap.Pins.Add(pin);
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.79752, -122.40183), Distance.FromMiles(1.0)));
}
}
}
}
我想这是所有需要的代码。我希望这是足够的。
我使用以下答案作为参考:
1条答案
按热度按时间dkqlctbz1#
你的代码有很多问题。
我想解决的只是与你提出的问题有关的问题。
它应该是
DATa
而不是Place
,您需要将属性声明为public
,并将其从lat
更改为Lat
,等等......