在创建对象时尝试使用lat / lon设置GeoCoordinate。 C#WP8

时间:2014-03-17 02:44:16

标签: c# windows-phone-8 visual-studio-2013

我正在使用来自API的json数据创建多个Bus对象。创建它们之后,我想创建一个GeoCoordinate来保存经度和纬度。我是C#的新手,似乎无法弄清楚为什么这不起作用?提前感谢任何意见。

 class Bus
{
        public string id { get; set; }
        public double longitude { get; set; }
        public double latitude { get; set; }
        public string route { get; set; }
        public string lastStop { get; set; }
        public GeoCoordinate busLocation { get; set; }



        public Bus()
        {
           GeoCoordinate busLocation = new GeoCoordinate(latitude, longitude);
         }
}

1 个答案:

答案 0 :(得分:0)

我不明白你的代码试图做什么。检查busLocation为null是没用的,它在构造函数被调用时始终为null。我想你想要实例化busLocation属性:

public Bus()
{
    busLocation = new GeoCoordinate();
}

以便稍后您可以为其LatitudeLongitude属性赋值,例如:

myBus.busLocation.Latitude = 50d;
myBus.busLocation.Longitude = 50d;