本文整理汇总了C#中CLLocationManager类的典型用法代码示例。如果您正苦于以下问题:C# CLLocationManager类的具体用法?C# CLLocationManager怎么用?C# CLLocationManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CLLocationManager类属于命名空间,在下文中一共展示了CLLocationManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
ConfigureView();
_iPhoneLocationManager = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
_iPhoneLocationManager.RequestWhenInUseAuthorization();
}
mapView.ShowsUserLocation = true;
if (mapView.UserLocationVisible)
{
UpdateUiCoords();
}
_iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer
mapView.DidUpdateUserLocation += (sender, e) =>
{
if (mapView.UserLocation != null)
{
CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude));
mapView.Region = new MKCoordinateRegion(coords, span);
UpdateUiCoords();
}
};
}
示例2: FinishedLaunching
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
global::Xamarin.FormsMaps.Init();
locationManager = new CLLocationManager
{
DesiredAccuracy = CLLocation.AccuracyBest
};
locationManager.Failed += (object sender, NSErrorEventArgs e) =>
{
var alert = new UIAlertView(){ Title = "Location manager failed", Message = "The location updater has failed" };
alert.Show();
locationManager.StopUpdatingLocation();
};
locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
{
var newloc = string.Format("{0},{1}", e.Locations[0].Coordinate.Longitude, e.Locations[0].Coordinate.Latitude);
App.Self.ChangedClass.BroadcastIt("location", newloc);
};
locationManager.StartUpdatingLocation();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
示例3: DoLocationAndUpdated
/// <summary>
/// get the location of user and update to server
/// </summary>
public static void DoLocationAndUpdated()
{
Location.iPhoneLocationManager = new CLLocationManager ();
Location.iPhoneLocationManager.DesiredAccuracy = 5; // 1000 meters/1 kilometer
// if this is iOs6
if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
Location.iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
CLLocation newLocation = e.Locations [e.Locations.Length - 1];
Utils.Log("ios6");
Location.UpdateLocationToServer(newLocation.Coordinate.Latitude.ToString (), newLocation.Coordinate.Longitude.ToString ());
//iPhoneLocationManager.StopUpdatingLocation();
};
}
// if it is iOs 5 or lower
else {
Location.iPhoneLocationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => {
CLLocation newLocation = e.NewLocation;
Utils.Log("ios5");
Location.UpdateLocationToServer(newLocation.Coordinate.Latitude.ToString (), newLocation.Coordinate.Longitude.ToString ());
//iPhoneLocationManager.StopUpdatingLocation();
};
}
if (CLLocationManager.LocationServicesEnabled) iPhoneLocationManager.StartUpdatingLocation ();
}
示例4: Start
public void Start ()
{
if (CLLocationManager.LocationServicesEnabled) {
lman = new CLLocationManager {
DesiredAccuracy = CLLocation.AccuracyBest,
};
lman.RequestWhenInUseAuthorization ();
lman.LocationsUpdated += (sender, e) => {
var loc = e.Locations [0];
Timestamp = loc.Timestamp;
Location = new Location (loc.Coordinate.Latitude, loc.Coordinate.Longitude, loc.Altitude);
// Console.WriteLine (Location);
HorizontalAccuracy = loc.HorizontalAccuracy;
VerticalAccuracy = loc.VerticalAccuracy;
LocationReceived (this, EventArgs.Empty);
};
lman.UpdatedHeading += (sender, e) => {
Heading = e.NewHeading.TrueHeading;
// Console.WriteLine ("Heading: {0}", Heading);
};
lman.StartUpdatingLocation ();
lman.StartUpdatingHeading ();
}
}
示例5: GPSTracker
public GPSTracker()
{
if (CLLocationManager.LocationServicesEnabled)
{
_manager = new CLLocationManager();
}
}
示例6: Init
public void Init(Action<PLVPaylevenStatus> action, string currency)
{
locationManager = new CLLocationManager();
// TODO: Get current location
paylevenManager = new PaylevenManager(action, currency, 52.252505, 21.023012);
}
示例7: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
int speedSystem = 0;
kmhourButton.ValueChanged += (sender,e) => {
speedSystem = kmhourButton.SelectedSegment;
};
_iPhoneLocationManager = new CLLocationManager ();
_iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer
//update location based on the specified metric system
_iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
UpdateLocation (speedSystem, e.Locations [e.Locations.Length - 1].Speed);
};
if (CLLocationManager.LocationServicesEnabled)
_iPhoneLocationManager.StartUpdatingLocation ();
//if viewmap button is touched then display the map
ViewMap.TouchUpInside += (object sender, EventArgs e) => {
if (_speedController == null)
_speedController = new SpeedController();
//_speedController = new MapController();
NavigationController.PushViewController(_speedController, true);
};
}
示例8: FinishedLaunching
public override void FinishedLaunching(UIApplication application)
{
locationManager = new CLLocationManager ();
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
locationManager.RequestWhenInUseAuthorization ();
}
// A user can transition in or out of a region while the application is not running.
// When this happens CoreLocation will launch the application momentarily, call this delegate method
// and we will let the user know via a local notification.
locationManager.DidDetermineState += (sender, e) => {
string body = null;
if (e.State == CLRegionState.Inside)
body = "You're inside the region";
else if (e.State == CLRegionState.Outside)
body = "You're outside the region";
if (body != null) {
var notification = new UILocalNotification () { AlertBody = body };
// If the application is in the foreground, it will get called back to ReceivedLocalNotification
// If its not, iOS will display the notification to the user.
UIApplication.SharedApplication.PresentLocalNotificationNow (notification);
}
};
}
示例9: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
locMan = new CLLocationManager();
locMan.RequestWhenInUseAuthorization();
locMan.RequestAlwaysAuthorization();
// Geocode a city to get a CLCircularRegion,
// and then use our location manager to set up a geofence
button.TouchUpInside += (o, e) => {
// clean up monitoring of old region so they don't pile up
if(region != null)
{
locMan.StopMonitoring(region);
}
// Geocode city location to create a CLCircularRegion - what we need for geofencing!
var taskCoding = geocoder.GeocodeAddressAsync ("Cupertino");
taskCoding.ContinueWith ((addresses) => {
CLPlacemark placemark = addresses.Result [0];
region = (CLCircularRegion)placemark.Region;
locMan.StartMonitoring(region);
});
};
// This gets called even when the app is in the background - try it!
locMan.RegionEntered += (sender, e) => {
Console.WriteLine("You've entered the region");
};
locMan.RegionLeft += (sender, e) => {
Console.WriteLine("You've left the region");
};
}
示例10: GeolocationSingleUpdateDelegate
public GeolocationSingleUpdateDelegate(CLLocationManager manager, double desiredAccuracy, bool includeHeading, int timeout, CancellationToken cancelToken)
{
this.manager = manager;
this.tcs = new TaskCompletionSource<Position>(manager);
this.desiredAccuracy = desiredAccuracy;
this.includeHeading = includeHeading;
if (timeout != Timeout.Infinite)
{
Timer t = null;
t = new Timer(s =>
{
if (this.haveLocation)
this.tcs.TrySetResult(new Position(this.position));
else
this.tcs.TrySetCanceled();
StopListening();
t.Dispose();
}, null, timeout, 0);
}
cancelToken.Register(() =>
{
StopListening();
this.tcs.TrySetCanceled();
});
}
示例11: LocationsUpdated
public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations)
{
Task.Run (async () => {await AppDelegate.FlicService.RefreshPendingConnections();});
foreach(var loc in locations) {
Console.WriteLine(loc);
}
}
示例12: LocationTestService
public LocationTestService()
{
locationManager = new CLLocationManager();
locationManager.LocationsUpdated += LocationsUpdated;
locationManager.DistanceFilter = 10;
locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
}
示例13: UpdatedLocation
public override void UpdatedLocation (CLLocationManager manager, CLLocation newLocation, CLLocation oldLocation)
{
_helper.Locations.Add (newLocation);
if (_helper.LocationAdded != null)
_helper.LocationAdded (_helper, new LocationEventArgs (newLocation));
}
示例14: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
locationManager = new CLLocationManager ();
locationManager.AuthorizationChanged += OnAuthorizationChanged;
locationManager.LocationsUpdated += OnLocationsUpdated;
locationManager.DesiredAccuracy = CLLocation.AccuracyBest;
locationManager.ActivityType = CLActivityType.Other;
// We setup a pair of anchors that will define how the floorplan image, maps to geographic co-ordinates
var anchor1 = new GeoAnchor {
LatitudeLongitude = new CLLocationCoordinate2D (37.770511, -122.465810),
Pixel = new CGPoint (12, 18)
};
var anchor2 = new GeoAnchor {
LatitudeLongitude = new CLLocationCoordinate2D (37.769125, -122.466356),
Pixel = new CGPoint (481, 815)
};
anchorPair = new Tuple<GeoAnchor, GeoAnchor> (anchor1, anchor2);
// Initialize the coordinate system converter with two anchor points.
coordinateConverter = new CoordinateConverter (anchorPair);
}
示例15: StartTimer
public void StartTimer(CLLocationManager manager)
{
hasLastAttempt = false;
Manager = manager;
locationTimer = NSTimer.CreateScheduledTimer(TimeSpan.FromSeconds(30), TerminateLocationUpdate);
}