单机器人GPS应用
在Monodroid中,我尝试访问GPS服务。我只需要一个定位对象 这一行显示一个错误:单机器人GPS应用,gps,xamarin.android,Gps,Xamarin.android,在Monodroid中,我尝试访问GPS服务。我只需要一个定位对象 这一行显示一个错误: _locationManager.RequestLocationUpdate(locationManager.GpsProvider,1000,10,本) Java.Lang.SecurityException 堆栈跟踪在以下位置显示:0中的Android.Runtime.JNIEnv.CallVoidMethod(IntPtr jobject,IntPtr jmethod,Android.Runtim
- _locationManager.RequestLocationUpdate(locationManager.GpsProvider,1000,10,本)李>
...
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Locations;
...
namespace mynamespace
{
[Activity(Label = "My Activity")]
public class MainActivity : Activity, ILocationListener
{
...
#region Location Variables
LocationManager _locationManager;
#endregion
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.MainPage);
...
#region Location Setup
try
{
_locationManager = null;
if (/*user says to use location services*/)
{
_locationManager = (LocationManager)GetSystemService(Context.LocationService);
_locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 1000, 10, this);
}
}
catch (Exception ex)
{
_debug.Text = string.Format("{0} -- {1}",ex.Message,ex.StackTrace);
}
#endregion
...
}
#region Common Methods
...
#endregion
#region Events
...
#endregion
#region Location Services
public void OnLocationChanged(Location location)
{
_debug.Text = string.Format("long: {0}, lat: {1}", location.Longitude, location.Latitude);
}
public void OnProviderDisabled(string provider)
{
//throw new NotImplementedException();
}
public void OnProviderEnabled(string provider)
{
//throw new NotImplementedException();
}
public void OnStatusChanged(string provider, int status, Bundle extras)
{
//throw new NotImplementedException();
}
#endregion
}
}
您的应用程序没有访问GPS的权限。要解决此项目上打开的上下文菜单问题,请选择属性->Android清单。如果没有任何内容,请单击链接“未找到AndroidMaifest.xml。单击以添加一个。”检查访问GPS数据的权限-访问位置。保存、重建、享受