gps 位置 xamarin android 不工作
gps location xamarin android not working
- 在列表 viewList 项目中使用此代码段获取 gps 位置但它不起作用(
public class ItemGeoLocationActivity : ListActivity, ILocationListener the class
)
请大家看看我做错了什么
[Activity(Label = "ItemGeoLocationActivity")]
public class ItemGeoLocationActivity : ListActivity, ILocationListener
{
LocationManager _locMgr;
private string Latitude;
private string Longitude;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
_locMgr = GetSystemService(Context.LocationService) as LocationManager;
list = new ItemGeoLocationAdapter(this);
this.ListAdapter = list;
}
protected override void OnListItemClick(ListView l, View v, int position, long id)
{
var item = this.list.GetItemAtPosition(position);
var builder = new AlertDialog.Builder(this);
builder.SetMessage(item.ItemName + "-- Latitude ="+Latitude+" Longitude="+Longitude);
builder.SetPositiveButton("OK", (s, e) =>
{
var itemGeoLocation =new ItemGeoLocation
{
ItemId = item.ItemId,
Langtitued = Convert.ToDecimal(Longitude),
Latitued = Convert.ToDecimal(Latitude)
};
new DataAccess().AddItemGeoLocation(itemGeoLocation);
Toast.MakeText(this, item.ItemName + "-- Recode Added Succesafully", ToastLength.Long).Show();
});
builder.SetNegativeButton("Cancel", (s, e) =>
{
Toast.MakeText(this, item.ItemName + " Save Cancelation Success!", ToastLength.Long).Show();
});
builder.Create().Show();
}
protected override void OnResume()
{
base.OnResume();
var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.NoRequirement;
locationCriteria.PowerRequirement = Power.NoRequirement;
string locationProvider = _locMgr.GetBestProvider(locationCriteria, true);
_locMgr.RequestLocationUpdates(locationProvider, 2000, 1, this);
}
protected override void OnPause()
{
base.OnPause();
_locMgr.RemoveUpdates(this);
}
#region ILocationListener implementation
public void OnLocationChanged(Location location)
{
Latitude = location.Latitude.ToString();
Longitude=location.Longitude.ToString();
}
public void OnProviderDisabled(string provider)
{
}
public void OnProviderEnabled(string provider)
{
}
public void OnStatusChanged(string provider, Availability status, Bundle extras)
{
}
}
我更换了模拟器,它成功了fine.Use
http://www.andyroid.net/ 安卓模拟器。它也支持 Xamarin
- 在列表 viewList 项目中使用此代码段获取 gps 位置但它不起作用(
public class ItemGeoLocationActivity : ListActivity, ILocationListener the class
)
请大家看看我做错了什么
[Activity(Label = "ItemGeoLocationActivity")]
public class ItemGeoLocationActivity : ListActivity, ILocationListener
{
LocationManager _locMgr;
private string Latitude;
private string Longitude;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
_locMgr = GetSystemService(Context.LocationService) as LocationManager;
list = new ItemGeoLocationAdapter(this);
this.ListAdapter = list;
}
protected override void OnListItemClick(ListView l, View v, int position, long id)
{
var item = this.list.GetItemAtPosition(position);
var builder = new AlertDialog.Builder(this);
builder.SetMessage(item.ItemName + "-- Latitude ="+Latitude+" Longitude="+Longitude);
builder.SetPositiveButton("OK", (s, e) =>
{
var itemGeoLocation =new ItemGeoLocation
{
ItemId = item.ItemId,
Langtitued = Convert.ToDecimal(Longitude),
Latitued = Convert.ToDecimal(Latitude)
};
new DataAccess().AddItemGeoLocation(itemGeoLocation);
Toast.MakeText(this, item.ItemName + "-- Recode Added Succesafully", ToastLength.Long).Show();
});
builder.SetNegativeButton("Cancel", (s, e) =>
{
Toast.MakeText(this, item.ItemName + " Save Cancelation Success!", ToastLength.Long).Show();
});
builder.Create().Show();
}
protected override void OnResume()
{
base.OnResume();
var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.NoRequirement;
locationCriteria.PowerRequirement = Power.NoRequirement;
string locationProvider = _locMgr.GetBestProvider(locationCriteria, true);
_locMgr.RequestLocationUpdates(locationProvider, 2000, 1, this);
}
protected override void OnPause()
{
base.OnPause();
_locMgr.RemoveUpdates(this);
}
#region ILocationListener implementation
public void OnLocationChanged(Location location)
{
Latitude = location.Latitude.ToString();
Longitude=location.Longitude.ToString();
}
public void OnProviderDisabled(string provider)
{
}
public void OnProviderEnabled(string provider)
{
}
public void OnStatusChanged(string provider, Availability status, Bundle extras)
{
}
}
我更换了模拟器,它成功了fine.Use http://www.andyroid.net/ 安卓模拟器。它也支持 Xamarin