在谷歌地图上创建叠加层

时间:2012-03-15 08:09:07

标签: google-maps xamarin.android

我正在使用monodevelop,并在这里引用这篇文章http://docs.xamarin.com/android/tutorials/Maps_and_Location/Part_2_-_Maps_API#Adding_Overlays_to_a_Map,我正在尝试为地图创建叠加层。我认为我遵循了教程所说的100%,但我收到了这个错误

Non-invocable member 'System.Collectios.Generic.List<Android.GoogleMaps.OverlayItem>.Count' cannot be used like a method.

这是我的完整代码。顺便说一下,错误是指第4行,返回_items.Count(); 。因为我只是按照教程

,我不知道我做错了什么
using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Android.Util;
using Android.GoogleMaps;

using System.Collections.Generic;
using Android.Graphics;
using Android.Graphics.Drawables;

namespace HelloM4A
{
    [Activity (Label = "HelloM4A")]
    public class Activity1 : MapActivity
    {

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

             MyLocationOverlay _myLocationOverlay;

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.MapLayout);

            var map = FindViewById<MapView>(Resource.Id.map);
            map.Clickable = true;
            //map.Traffic = true;
            map.Satellite = true;
            map.SetBuiltInZoomControls (true);
            map.Controller.SetZoom (10);
            map.Controller.SetCenter (new GeoPoint ((int)(2.925088 * 1E6), (int)(101.657381 * 1E6)));


            var aButton = FindViewById<Button> (Resource.Id.aButton); 

             aButton.Click += (sender, e) => {
                 _myLocationOverlay = new MyLocationOverlay (this, map);
                map.Overlays.Add (_myLocationOverlay);
             };  

        }

         protected override bool IsRouteDisplayed {
              get {
                      return false;              }
        }
    }

    class MonkeyItemizedOverlay: ItemizedOverlay
    {
           List<OverlayItem> _items;

           public MonkeyItemizedOverlay (Drawable Icon) : base(Icon)
           {     
                  // populate some sample location data for the overlay items
                  _items = new List<OverlayItem>{
                          new OverlayItem (new GeoPoint ((int)40.741773E6,
                                 (int)-74.004986E6), null, null),
                          new OverlayItem (new GeoPoint ((int)41.051696E6,
                                 (int)-73.545667E6), null, null),
                          new OverlayItem (new GeoPoint ((int)41.311197E6,
                                 (int)-72.902646E6), null, null)
                  };

                  BoundCenterBottom(Icon);
                  Populate();
           }

        protected override Java.Lang.Object CreateItem (int i)
        {
               var item = _items[i];
               return item;
        }

        public override int Size ()
        {
               return _items.Count();
        }             
    }
}

1 个答案:

答案 0 :(得分:1)

List<T>.Count是一个属性,但您尝试调用它,就像它是一个方法一样。更新您的尺寸方法如下所示:

public override int Size()
{
    return _items.Count;
}