本文整理汇总了C#中Android.Locations.LocationManager.RequestLocationUpdates方法的典型用法代码示例。如果您正苦于以下问题:C# LocationManager.RequestLocationUpdates方法的具体用法?C# LocationManager.RequestLocationUpdates怎么用?C# LocationManager.RequestLocationUpdates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Locations.LocationManager
的用法示例。
在下文中一共展示了LocationManager.RequestLocationUpdates方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnResume
protected override void OnResume()
{
base.OnResume();
// LocationManagerを初期化
locMgr = GetSystemService(Context.LocationService) as LocationManager;
button.Click += (sender, e) =>
{
if (locMgr.AllProviders.Contains(LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled(LocationManager.NetworkProvider))
{
// Network: Wifiと3Gで位置情報を取得します。電池使用量は少ないですが精度にばらつきがあります。
Log.Debug(tag, "Starting location updates with Network");
locMgr.RequestLocationUpdates(LocationManager.NetworkProvider, 10000, 10, this);
}
else
{
// GetBestProviderで最適なProviderを利用できるようです。(NetworkがあればそれがBestProviderになるようです。)
var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.Coarse;
locationCriteria.PowerRequirement = Power.Medium;
string locationProvider = locMgr.GetBestProvider(locationCriteria, true);
Log.Debug(tag, "Starting location updates with " + locationProvider.ToString());
locMgr.RequestLocationUpdates(locationProvider, 10000, 10, this);
}
};
}
示例2: GetLocation
public Location GetLocation() {
try {
locationManager = (LocationManager)mContext.GetSystemService("location");
// Getting GPS status
isGPSEnabled = locationManager.IsProviderEnabled(LocationManager.GpsProvider);
// Getting network status
isNetworkEnabled = locationManager.IsProviderEnabled(LocationManager.NetworkProvider);
if (!isGPSEnabled && !isNetworkEnabled) {
//showalert in activity
}
else {
this.CanGetLocation = true;
if (isNetworkEnabled) {
locationManager.RequestLocationUpdates(
LocationManager.NetworkProvider,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);
if (location != null) {
latitude = location.Latitude;
longitude = location.Longitude;
}
}
}
if (isGPSEnabled) {
if (location == null) {
locationManager.RequestLocationUpdates(
LocationManager.GpsProvider,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider);
if (location != null) {
latitude = location.Latitude;
longitude = location.Longitude;
}
}
}
}
}
} catch (Exception e) {
AlertsService.ShowToast(this.mContext, "Nie masz w³¹czonej lokalizacji!");
}
return location;
}
示例3: start
public void start()
{
if (_tracking) return;
var ls = (LocationManager) _context.GetSystemService(Context.LocationService);
//var aproviders = ls.AllProviders.ToArray();
//var hasGPS = ls.IsProviderEnabled(LocationManager.GpsProvider);
//var hasNET = ls.IsProviderEnabled(LocationManager.NetworkProvider);
//if (!hasGPS || !hasNET)
{
//throw new Exception("Must have both GPS and Net location providers");
}
_locationManager = ls;
var lastLocation = _locationManager.GetLastKnownLocation(LocationManager.PassiveProvider);
Location = createGeoLocation(lastLocation);
var criteria = new Criteria();
criteria.Accuracy = Accuracy.Fine;
criteria.AltitudeRequired = true;
var providers = _locationManager.GetProviders(criteria, true).ToArray();
foreach (var provider in providers)
{
_locationManager.RequestLocationUpdates(provider, 1000, 5, _listener, Looper.MainLooper);
}
_tracking = true;
}
示例4: OnResume
// OnResume gets called every time the activity starts, so we'll put our RequestLocationUpdates
// code here, so that
protected override void OnResume ()
{
base.OnResume ();
Log.Debug (tag, "OnResume called");
// initialize location manager
locMgr = GetSystemService (Context.LocationService) as LocationManager;
button.Click += delegate {
button.Text = "Location Service Running";
// pass in the provider (GPS),
// the minimum time between updates (in seconds),
// the minimum distance the user needs to move to generate an update (in meters),
// and an ILocationListener (recall that this class impletents the ILocationListener interface)
locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);
// Comment the line above, and uncomment the following, to test
// the GetBestProvider option. This will determine the best provider
// at application launch. Note that once the provide has been set
// it will stay the same until the next time this method is called
/*var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.Coarse;
locationCriteria.PowerRequirement = Power.Medium;
string locationProvider = locMgr.GetBestProvider(locationCriteria, true);
Log.Debug(tag, "Starting location updates with " + locationProvider.ToString());
locMgr.RequestLocationUpdates (locationProvider, 2000, 1, this);*/
};
}
示例5: PlatformSpecificStart
protected override void PlatformSpecificStart(MvxLocationOptions options)
{
if (_locationManager != null)
throw new MvxException("You cannot start the MvxLocation service more than once");
_locationManager = (LocationManager)Context.GetSystemService(Context.LocationService);
if (_locationManager == null)
{
MvxTrace.Warning("Location Service Manager unavailable - returned null");
SendError(MvxLocationErrorCode.ServiceUnavailable);
return;
}
var criteria = new Criteria()
{
Accuracy = options.Accuracy == MvxLocationAccuracy.Fine ? Accuracy.Fine : Accuracy.Coarse,
};
_bestProvider = _locationManager.GetBestProvider(criteria, true);
if (_bestProvider == null)
{
MvxTrace.Warning("Location Service Provider unavailable - returned null");
SendError(MvxLocationErrorCode.ServiceUnavailable);
return;
}
_locationManager.RequestLocationUpdates(
_bestProvider,
(long)options.TimeBetweenUpdates.TotalMilliseconds,
options.MovementThresholdInM,
_locationListener);
}
示例6: GetCurrentLocation
protected override void GetCurrentLocation()
{
locationManager = context.GetSystemService(Context.LocationService) as LocationManager;
if (locationManager.IsProviderEnabled(LocationManager.GpsProvider))
locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);
}
示例7: OnCreate
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
nameEditText = FindViewById<EditText>(Resource.Id.firstNameTextField);
surnameEditText = FindViewById<EditText>(Resource.Id.surNameTextField);
locM = GetSystemService(Context.LocationService) as LocationManager;
if (locM.IsProviderEnabled(LocationManager.GpsProvider))
locM.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);
Button notificationButton1 = FindViewById<Button>(Resource.Id.notificationButton1);
Button notificationButton2 = FindViewById<Button>(Resource.Id.notificationbutton2);
Button notificationButton3 = FindViewById<Button>(Resource.Id.notificationbutton3);
Button notificationButton4 = FindViewById<Button>(Resource.Id.notificationbutton4);
Button notificationButton5 = FindViewById<Button>(Resource.Id.notificationbutton5);
textView = FindViewById<TextView>(Resource.Id.textView2);
notificationButtons = new Button[] { notificationButton1, notificationButton2, notificationButton3, notificationButton4, notificationButton5 };
foreach (Button button in notificationButtons)
{
button.Enabled = false;
button.Click += SendNotification;
}
}
示例8: OnCreate
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionLocal;
AndroidEnvironment.UnhandledExceptionRaiser += HandleAndroidException;
Xamarin.Forms.Forms.Init (this, bundle);
Forms.Init(this, bundle);
FormsMaps.Init(this, bundle);
_locationManager = GetSystemService (Context.LocationService) as LocationManager;
Criteria locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.Coarse;
locationCriteria.PowerRequirement = Power.Medium;
var locationProvider = _locationManager.GetBestProvider(locationCriteria, true);
if(locationProvider != null)
{
_locationManager.RequestLocationUpdates (locationProvider, 500, 1, this);
}
var pclApp = App.Portable.App.Instance;
var setup = new AppSetup () {
CreateConnectionPool = this.CreateConnnectionPool,
DbPath = Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal),"RF12G5td864.db3")
};
pclApp.Setup (setup);
#if DEBUG
//pclApp.DeleteUser ();
#endif
LoadApplication (pclApp);
}
示例9: Locator
public Locator(Activity ctx)
{
this.ctx = ctx;
locationManager = (LocationManager)ctx.GetSystemService (Context.LocationService);
locationManager.RequestLocationUpdates (LocationManager.PassiveProvider, 5 * 60 * 1000, 2, this);
if (Geocoder.IsPresent)
geocoder = new Geocoder (ctx);
}
示例10: InitializeLocationManager
void InitializeLocationManager()
{
locMgr = GetSystemService (Context.LocationService) as LocationManager;
if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 0, 0, this);
} else {
MApplication.getInstance().longitude = 0;
MApplication.getInstance().latitude = 0;
}
}
示例11: OnResume
protected override void OnResume ()
{
base.OnResume ();
// Get a handle on the map element
_mapFragment = FragmentManager.FindFragmentById(Resource.Id.map) as MapFragment;
_map = _mapFragment.Map;
// Set the map type
_map.MapType = GoogleMap.MapTypeNormal;
// show user location
_map.MyLocationEnabled = true;
// setup a location manager
_locationManager = GetSystemService(Context.LocationService) as LocationManager;
// TODO: Step 3b - Add points on the map
// MarkerOptions marker1 = new MarkerOptions()
// .SetPosition(Location_Xamarin)
// .SetTitle("Xamarin")
// .InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueBlue));
// _map.AddMarker(marker1);
//
// MarkerOptions marker2 = new MarkerOptions()
// .SetPosition(Location_Atlanta)
// .SetTitle("Atlanta, GA")
// .InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed));
// _map.AddMarker(marker2);
// TODO: Step 3c - Add custom marker images on the map
// AddMonkeyMarkersToMap();
// TODO: Step 3d - Add custom arrow callout on map
// AddInitialNewYorkBarToMap();
// TODO: Step 3e - Add custom overlay image on the map
// PositionChicagoGroundOverlay(Location_Chicago);
// use a generic location provider instead
Criteria locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.Coarse;
locationCriteria.PowerRequirement = Power.Medium;
var locationProvider = _locationManager.GetBestProvider(locationCriteria, true);
if (locationProvider != null)
{
_locationManager.RequestLocationUpdates(locationProvider, 2000, 1, this);
} else
{
Log.Info("error", "Best provider is not available. Does the device have location services enabled?");
}
}
示例12: OnResume
protected override void OnResume()
{
base.OnResume ();
locMgr = GetSystemService (Context.LocationService) as LocationManager;
if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);
} else {
Toast.MakeText (this, "The Network Provider does not exist or is not enabled!", ToastLength.Long).Show ();
}
}
示例13: StartService
public void StartService()
{
_locMan = Application.Context.GetSystemService (Context.LocationService) as LocationManager;
if (_locMan.GetProvider (LocationManager.GpsProvider) != null && _locMan.IsProviderEnabled (LocationManager.GpsProvider))
{
_pi = PendingIntent.GetBroadcast(Application.Context, 0, new Intent(), PendingIntentFlags.UpdateCurrent);
_locMan.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 5, _pi);
_locMan.GetLastKnownLocation (LocationManager.GpsProvider);
}
else
throw new GPSNotEnabledException (Const.NO_GPS_ERROR_MESSAGE);
}
示例14: StartLocationUpdates
/// <summary>
/// This method activates the Android LocationManager and begins reporting
/// location changes through our own LocationChanged event.
/// </summary>
public void StartLocationUpdates()
{
locMgr = Application.Context.GetSystemService("location") as LocationManager;
if (locMgr == null)
return;
var locationCriteria = new Criteria() {
Accuracy = Accuracy.NoRequirement,
PowerRequirement = Power.NoRequirement
};
var locationProvider = locMgr.GetBestProvider(locationCriteria, true);
locMgr.RequestLocationUpdates(locationProvider, 2000, 0, this);
}
示例15: OnStart
public override void OnStart (Android.Content.Intent intent, int startId)
{
base.OnStart (intent, startId);
DBRepository dbr = new DBRepository ();
userAndsoft = dbr.getUserAndsoft ();
userTransics = dbr.getUserTransics ();
var t = DateTime.Now.ToString("dd_MM_yy");
string dir_log = (Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads)).ToString();
ISharedPreferences pref = Application.Context.GetSharedPreferences("AppInfo", FileCreationMode.Private);
string log = pref.GetString("Log", String.Empty);
//GetTelId
TelephonyManager tel = (TelephonyManager)this.GetSystemService(Context.TelephonyService);
var telId = tel.DeviceId;
//Si il n'y a pas de shared pref
if (log == String.Empty){
log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt");
ISharedPreferencesEditor edit = pref.Edit();
edit.PutString("Log",log_file);
edit.Apply();
}else{
//il y a des shared pref
log_file = pref.GetString("Log", String.Empty);
if (((File.GetCreationTime(log_file)).CompareTo(DateTime.Now)) > 3) {
File.Delete(log_file);
log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt");
ISharedPreferencesEditor edit = pref.Edit();
edit.PutString("Log",log_file);
edit.Apply();
log_file = pref.GetString("Log", String.Empty);
}
}
File.AppendAllText(log_file,"[SERVICE] Service Onstart call "+DateTime.Now.ToString("t")+"\n");
DoStuff ();
// initialize location manager
locMgr = GetSystemService (Context.LocationService) as LocationManager;
if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);
File.AppendAllText(log_file,"[GPS] Lancer le"+DateTime.Now.ToString("t")+"\n");
} else {
File.AppendAllText(log_file,"[GPS] Le GPS est désactiver"+DateTime.Now.ToString("t")+"\n");
}
}