Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android OnLocationChanged从未被调用_Android - Fatal编程技术网

Android OnLocationChanged从未被调用

Android OnLocationChanged从未被调用,android,Android,我有以下代码- 在此处输入代码 使用制度; 使用System.Collections.Generic; 使用系统文本; 使用Android.App; 使用Android.Content; 使用Android.Runtime; 使用Android.Views; 使用Android.Widget; 使用Android.OS; 使用Android.Locations; 使用Android.Bluetooth namespace GetCurrentLocation { [Activity(La

我有以下代码-
在此处输入代码

使用制度; 使用System.Collections.Generic; 使用系统文本; 使用Android.App; 使用Android.Content; 使用Android.Runtime; 使用Android.Views; 使用Android.Widget; 使用Android.OS; 使用Android.Locations; 使用Android.Bluetooth

namespace GetCurrentLocation
{
    [Activity(Label = "Get Current Location", MainLauncher = true, Icon = "@drawable/icon")]
    public class Activity1 : Activity, ILocationListener
    {
        LocationManager _locMgr ;
        String oBestProvider;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            _locMgr = GetSystemService(Context.LocationService) as LocationManager;

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.UI);
            StringBuilder strLocations = new StringBuilder();
            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.btnGetLocation);
            int i;
            var locationText =
                FindViewById<TextView>(Resource.Id.txtLocation);

                Android.Locations.Location oLocation;

            oLocation = _locMgr.GetLastKnownLocation (Context.LocationService);
            IList<String> oLocationProviders = _locMgr.GetProviders(true);

            //Location location;
            button.Click += delegate {
                if(oLocationProviders != null)
                    {

                _locMgr.RequestLocationUpdates(oLocationProviders[0], 2000, 1, this);
                _locMgr.RequestLocationUpdates(oLocationProviders[1], 2000, 1, this);


                    }
                    else{

                    locationText.Text ="No Provider Found";
                    }

            };

        }



        protected override void OnResume() {
            base.OnResume();

        }

        protected override void OnPause() {
            base.OnPause ();
            _locMgr.RemoveUpdates(this);
        }

        public void OnLocationChanged (Location location)
        {

            var locationText =
                   FindViewById<TextView> (Resource.Id.txtLocation);
            if (location != null) {
                locationText.Text = String.Format ("Latitude = {0}, Longitude = {1}",
                   location.Latitude, location.Longitude);
            }
        }

        public void OnProviderDisabled(string provider)
        {

        }

        public void OnProviderEnabled(string provider)
        {
        }

        public void OnStatusChanged(string provider, Availability status, Bundle extras)
        {
        }

    }
}
命名空间GetCurrentLocation
{
[活动(Label=“获取当前位置”,MainLauncher=true,Icon=“@drawable/Icon”)]
公共类活动1:活动,ILocationListener
{
地点经理(地点经理);
串出器;
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
_locMgr=GetSystemService(Context.LocationService)作为LocationManager;
//从“主”布局资源设置视图
SetContentView(Resource.Layout.UI);
StringBuilder strLocations=新StringBuilder();
//从布局资源中获取我们的按钮,
//并在其上附加一个事件
Button Button=FindViewById(Resource.Id.btnGetLocation);
int i;
变量位置文本=
findviewbyd(Resource.Id.txtLocation);
Android.Locations.Location位置;
oLocation=\u locMgr.GetLastKnownLocation(Context.LocationService);
IList-oLocationProviders=\u locMgr.GetProviders(true);
//位置;
按钮。单击+=委派{
if(oLocationProviders!=null)
{
_locMgr.RequestLocationUpdate(oLocationProviders[0],2000,1,本);
_locMgr.RequestLocationUpdate(oLocationProviders[1],2000,1,this);
}
否则{
locationText.Text=“未找到提供程序”;
}
};
}
受保护的覆盖void OnResume(){
base.OnResume();
}
受保护的覆盖void OnPause(){
base.OnPause();
_Locamgr.RemoveUpdate(本);
}
已更改位置上的公共无效(位置)
{
变量位置文本=
findviewbyd(Resource.Id.txtLocation);
如果(位置!=null){
locationText.Text=String.Format(“纬度={0},经度={1}”,
位置、纬度、位置、经度);
}
}
公共无效OnProviderDisabled(字符串提供程序)
{
}
公共无效OnProviderEnabled(字符串提供程序)
{
}
public void OnStatusChanged(字符串提供程序、可用性状态、捆绑附加)
{
}
}
}
我尝试过使用GetBestProvider/GetProviders/RequestLocationUpdates/GetLastKnownLocation。我不能继续。有人能告诉我为什么我的OnLocationUpdates从来没有被呼叫过吗。即使类活动正在实现ILocationListener接口,我也无法在此函数上使用Override关键字。请帮忙。。。。。
另外,仅供参考,我正试图在谷歌的Nexus5试用版仿真器AVD上运行这段代码

如果您在emulator上运行,那么onLocationChanged将永远不会被调用,除非您从DDMS提供位置。从DDMS中,您需要给出纬度和经度,以便它调用所需的方法


请在开放区域查看真实设备上的代码。

我想你的意思是Nexus 4/Nexus S。Nexus 5尚未发布。;-)我从Xamarin商店下载了我的试用版,那里说免费版将提供一个Xamarin studio,它是MonoDevelop,并且能够部署到设备上。store.xamarin.com。。。。。我不能使用部署到设备的功能而不是购买完整的Monodevelop。使用play store中的假gps应用程序吗