本文整理汇总了C#中Android.Locations.LocationManager.GetBestProvider方法的典型用法代码示例。如果您正苦于以下问题:C# LocationManager.GetBestProvider方法的具体用法?C# LocationManager.GetBestProvider怎么用?C# LocationManager.GetBestProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Locations.LocationManager
的用法示例。
在下文中一共展示了LocationManager.GetBestProvider方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LocationTracker
/// <summary>
/// コンストラクタ
/// </summary>
/// <param name="context"></param>
public LocationTracker(Context context, string provider = LocationManager.GpsProvider)
{
locationMan = (LocationManager)context.GetSystemService(Service.LocationService);
if(locationMan.GetProviders(true).Contains(provider))
{
Provider = provider;
}
else if (locationMan.IsProviderEnabled(LocationManager.GpsProvider))
{
Provider = LocationManager.GpsProvider;
}
else if (locationMan.IsProviderEnabled(LocationManager.NetworkProvider))
{
Provider = LocationManager.NetworkProvider;
}
else
{
Criteria crit = new Criteria();
crit.Accuracy = Accuracy.Fine;
Provider = locationMan.GetBestProvider(crit, true);
}
LastGPSReceived = DateTime.MinValue;
}
示例2: 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);
}
示例3: 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);
}
};
}
示例4: 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);
}
示例5: 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;
// 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);
// Add custom marker images on the map
AddMonkeyMarkersToMap();
// Add custom arrow callout on map
AddInitialNewYorkBarToMap();
// 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?");
}
// TODO: Step 4a - attach map handler for marker touch
// _map.MarkerClick += MapOnMarkerClick;
// TODO: Step 4c - attach map handler for info window touch
// _map.InfoWindowClick += HandleInfoWindowClick;
}
示例6: 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);
}
示例7: GetBestLocationProvider
private string GetBestLocationProvider(LocationManager lm)
{
Criteria cri = new Criteria();
cri.Accuracy = Accuracy.Coarse;
cri.PowerRequirement = Power.Low;
cri.AltitudeRequired = false;
cri.BearingAccuracy = Accuracy.Low;
cri.CostAllowed = false;
cri.HorizontalAccuracy = Accuracy.Low;
cri.SpeedAccuracy = Accuracy.Low;
cri.SpeedRequired = false;
cri.VerticalAccuracy = Accuracy.Low;
string pidStr = lm.GetBestProvider(cri, true);
return pidStr;
}
示例8: GetLocation
public void GetLocation()
{
_locationManager = Application.Context.GetSystemService(Context.LocationService) as LocationManager;
var 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);
}
}
示例9: LocListener
public LocListener(LocationManager lm, SensorManager sm) : base()
{
// Get LocationManager
locManager = lm;
var locationCriteria = new Criteria ()
{
Accuracy = global::Android.Locations.Accuracy.Fine,
AltitudeRequired = true,
PowerRequirement = Power.Low
};
locationProvider = locManager.GetBestProvider(locationCriteria, true);
if (locationProvider == null)
throw new Exception("No location provider found");
List<String> providers = locManager.GetProviders(true) as List<String>;
// Loop over the array backwards, and if you get an accurate location, then break out the loop
Location loc = null;
if (providers != null) {
for (int i = providers.Count - 1; i >= 0; i--) {
loc = locManager.GetLastKnownLocation(providers[i]);
if (loc != null)
break;
}
}
if (loc != null)
{
lat = loc.Latitude;
lon = loc.Longitude;
alt = loc.Altitude;
accuracy = loc.Accuracy;
}
sensorManager = sm;
accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
magnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField);
}
示例10: 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;
#region Show Location
// TODO: Step 2a - show user location
_map.MyLocationEnabled = true;
_map.UiSettings.MyLocationButtonEnabled = true;
#endregion
#region Setup Location Manager
// TODO: Step 2b - setup a location manager
_locationManager = GetSystemService(Context.LocationService) as LocationManager;
#endregion
#region Get Location Provider
// TODO: Step 2d - use a generic location provider
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);
}
#endregion
}
示例11: PlatformSpecificStart
protected override void PlatformSpecificStart(MvxGeoLocationOptions 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.EnableHighAccuracy ? Accuracy.Fine : Accuracy.Coarse};
var bestProvider = _locationManager.GetBestProvider(criteria, true);
if (bestProvider == null)
{
MvxTrace.Warning( "Location Service Provider unavailable - returned null");
SendError(MvxLocationErrorCode.ServiceUnavailable);
return;
}
_locationManager.RequestLocationUpdates(bestProvider, 5000, 2, _locationListener);
// TODO - Ideally - _geoWatcher.MovementThreshold needed too
}
示例12: 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;
_map.UiSettings.MyLocationButtonEnabled = true;
_map.MyLocationEnabled = true;
_locationManager = GetSystemService(Context.LocationService) as LocationManager;
// string Provider = LocationManager.GpsProvider;
// if(_locationManager.IsProviderEnabled(Provider))
// {
// _locationManager.RequestLocationUpdates (Provider, 2000, 1, this);
// }
// else
// {
// Log.Info("error", Provider + " is not available. Does the device have location services enabled?");
// }
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?");
}
}
示例13: OnCreate
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.location_demo);
_builder = new StringBuilder();
_geocoder = new Geocoder(this);
_locationText = FindViewById<TextView>(Resource.Id.location_text);
_locationManager = (LocationManager)GetSystemService(LocationService);
var criteria = new Criteria() { Accuracy = Accuracy.NoRequirement };
string bestProvider = _locationManager.GetBestProvider(criteria, true);
Location lastKnownLocation = _locationManager.GetLastKnownLocation(bestProvider);
if (lastKnownLocation != null)
{
_locationText.Text = string.Format("Last known location, lat: {0}, long: {1}",
lastKnownLocation.Latitude, lastKnownLocation.Longitude);
}
_locationManager.RequestLocationUpdates(bestProvider, 5000, 2, this);
}
示例14: OnResume
protected override void OnResume()
{
base.OnResume();
locMgr = GetSystemService(Context.LocationService) as LocationManager;
#if DEBUG
// 利用可能な LocationManager の Provider とオンオフをチェック
foreach (var item in locMgr.AllProviders)
{
Log.Debug("NetworkList", "Provider: " + item.ToString());
Log.Debug("NetworkList", "Avalable: " + locMgr.IsProviderEnabled(item.ToString()));
}
#endif
button.Click += (sender, e) =>
{
if (button.Text.ToUpper() == "GET LOCATION")
{
button.Text = "Location Service Running";
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 があればそれが Best になるようです。)
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);
}
}
else
{
Log.Debug(tag, "Stop locMgr manually");
locMgr.RemoveUpdates(this);
button.Text = "Get Location";
}
};
}
示例15: InitSensors
private void InitSensors()
{
locationManager = GetSystemService(LocationService) as LocationManager;
if (locationManager != null)
{
var provider = locationManager.GetBestProvider(new Criteria(), true);
locationManager.RequestLocationUpdates(provider, 50, 0, this);
}
world.StartSensors();
}