由于保护级别,无法将变量传递给 c# 中的对象

Cannot pass variable to object in c# due to protection level

我有这个代码,并尝试将两个参数传递给 LatLng(如果硬编码它工作正常),但由于其保护级别无法继续获取 - 在 var location = new LatLng 上...

我的封装有什么问题吗?

namespace SomeApp
{
    [Activity (Label = "App")]          
    public class MapActivity : Activity
    {
        protected override void OnCreate (Bundle savedInstanceState)
        {
            base.OnCreate (savedInstanceState);
            SetContentView(Resource.Layout.MapLayout);

            MapLocationSetup ();

        }

        public void MapLocationSetup () {

            string currentLocationLatitude = Intent.GetStringExtra ("currentLocationLatitude");
            string currentLocationLongitude = Intent.GetStringExtra ("currentLocationLongitude");

            var location = new LatLng(currentLocationLatitude, currentLocationLongitude);
            CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
            builder.Target(location);
            builder.Zoom(18);
            builder.Bearing(155);
            builder.Tilt(85);
            CameraPosition cameraPosition = builder.Build();
            CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition);

            MapFragment mapFrag = (MapFragment) FragmentManager.FindFragmentById(Resource.Id.mapLayout);
            GoogleMap map = mapFrag.Map;
            if (map != null) {
                map.MoveCamera(cameraUpdate);
                //map.MapType = GoogleMap.MapTypeSatellite;
            }
        }
    }
}

Android 的 LatLng 构造函数需要一个双精度值,而您传递的是一个字符串。这应该给您一个类型转换错误,而不是保护级别错误,但这似乎是基本问题。

string currentLocationLatitude = Intent.GetStringExtra ("currentLocationLatitude");
string currentLocationLongitude = Intent.GetStringExtra ("currentLocationLongitude");

double lat = Double.Parse(currentLocationLatitude);
double lng = Double.Parse(currentLocationLongitude);

var location = new LatLng(lat, lng);