コード例 #1
0
        void initLocationManager()
        {
            if (locationManager != null)
            {
                return;
            }

            locationManager = new CoreLocation.CLLocationManager();
            locationManager.DesiredAccuracy = 500; //500m

            if (UIDevice.CurrentDevice.CheckSystemVersion(6, 0))
            {
                locationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
                {
                    var location = e.Locations[e.Locations.Length - 1];
                    this.doOnLocationUpdated(new Location(location.Coordinate.Latitude, location.Coordinate.Longitude));
                };
            }
            else
            {
#pragma warning disable 618
                // this won't be called on iOS 6 (deprecated)
                locationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) =>
                {
                    var location = e.NewLocation;
                    this.doOnLocationUpdated(new Location(location.Coordinate.Latitude, location.Coordinate.Longitude));
                };
#pragma warning restore 618
            }
        }
コード例 #2
0
ファイル: EnableLocation.cs プロジェクト: tyenss/Drivery
        public EnableLocation()
        {
            ViewController vc  = new ViewController("RestaurantMap");
            Maps           map = vc.getMap();

            CoreLocation.CLLocationManager locationManager = new CoreLocation.CLLocationManager();
            locationManager.RequestWhenInUseAuthorization();
            map.IsShowingUser = true;

            // add an annotation

            /*map.AddAnnotations (new MKPointAnnotation (){
             *  Title="MyAnnotation",
             *  Coordinate = new CoreLocation.CLLocationCoordinate2D(42.364260, -71.120824)
             * });*/
        }
コード例 #3
0
ファイル: ViewController.cs プロジェクト: stephbu/stayorgo
        public ViewController(IntPtr handle) : base(handle)
        {
            OBADataProvider.Options opt = new OBADataProvider.Options {
                URL = new Uri("http://api.pugetsound.onebusaway.org"), APIKey = "efdf5397-9338-447c-832a-ac93ad4c9151"
            };
            ob = new OBADataProvider(opt);
            CancellationTokenSource cts = new CancellationTokenSource();

            this.locationManager = CreateLocationManager();
            this.locationManager.LocationsUpdated += LocationManager_InitialLocationUpdated;
            this.locationManager.RequestLocation();

            dataPump = new Task(async() => await ob.Pump(cts.Token, this.GetClientLocation, this.OnTrip));

            this.routeTableSource = new RouteTableViewSource(ob, this);
            this.routeTableSource.OnRoutesChanged += RouteTableSource_OnRoutesChanged;
        }
コード例 #4
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            // Member variable in the class
            // Save a reference to the CLLocationManager so that it stays in scope

            // Some method in the class
            // Request geoloation authorization
            locationManager = new CoreLocation.CLLocationManager();
            if (locationManager.RespondsToSelector (new ObjCRuntime.Selector("requestWhenInUseAuthorization")))
            {
             locationManager.RequestWhenInUseAuthorization ();
            }

            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }
コード例 #5
0
        public LocationManager()
        {
            this.locMgr = new CLLocationManager
            {
                PausesLocationUpdatesAutomatically = false
            };

            // iOS 8 has additional permissions requirements
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locMgr.RequestAlwaysAuthorization(); // works in background
                                                     //locMgr.RequestWhenInUseAuthorization (); // only in foreground
            }

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                locMgr.AllowsBackgroundLocationUpdates = true;
            }
        }
コード例 #6
0
 private MyLocation()
 {
     mLocationManager = new CoreLocation.CLLocationManager();
 }