// ILocationListener is a way for the Service to subscribe for updates
        // from the System location Service

        public void OnLocationChanged(Android.Locations.Location location)
        {
            this.LocationChanged(this, new LocationChangedEventArgs(location));
            var    nMgr         = (NotificationManager)GetSystemService(NotificationService);
            var    animal       = GetNearestAnimal(location);
            var    notification = new Notification(Resource.Drawable.Icon, "Message from JungleExplorer");
            var    intent       = new Intent(this, typeof(MainActivity));
            Bundle b            = new Bundle();

            b.PutInt("id", animal.ID);
            intent.PutExtras(b);
            //	PendingIntent contentIntent = PendingIntent.GetActivity(Context, animal.ID, intent, 0);
            id = animal.ID;
            var prefs = PreferenceManager.GetDefaultSharedPreferences(this);
            var send  = prefs.GetBoolean("notifications", true);

            if (send)
            {
                var pendingIntent = PendingIntent.GetActivity(this, animal.ID, intent, 0);
                notification.SetLatestEventInfo(this, "Jungle Explorer Notification", "Animal near to you!, id: " + animal.ID, pendingIntent);
                nMgr.Notify(0, notification);
            }
            //AppWidgetManager a = AppWidgetManager.GetInstance (this);
            SendInfoToWidget(animal.ID);
            //a.UpdateAppWidget ();
        }
Ejemplo n.º 2
0
        void MLocationCallback_MyLocation(object sender, LocationCallbackHelper.OnLocationCapturedEventArgs e)
        {
            mLastLocation = e.Location;
            LatLng myposition = new LatLng(mLastLocation.Latitude, mLastLocation.Longitude);

            myMap.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(myposition, 12));
        }
        Animal GetNearestAnimal(Android.Locations.Location location)
        {
            var animals = DataManager.Instance.GetAllAnimals();
            var animal  = new Animal();

            animal.ID = 0;
            float distance  = float.MaxValue;
            bool  firstTime = true;

            foreach (var a in animals)
            {
                float d = GetSquareDistance(a, location);
                if (d < distance)
                {
                    animal   = a;
                    distance = d;
                }
                if (firstTime)
                {
                    animal    = a;
                    distance  = d;
                    firstTime = false;
                }
            }
            return(animal);
        }
Ejemplo n.º 4
0
        private void BPLocationButton_Click(object sender, EventArgs eventArgs)
        {
            GPSTracker GPSTracker = new GPSTracker();

            Android.Locations.Location location = GPSTracker.GPSCoordinate();
            if (!GPSTracker.isLocationGPSEnabled)
            {
                ShowSettingsAlert();
            }
            if (location == null)
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.SendToast("Unable to get location");
            }
            else
            {
                BoundryPolygon BoundryPolygon = new BoundryPolygon()
                {
                    Latitude  = location.Latitude.ToString(),
                    Longitude = location.Longitude.ToString()
                };
                _BoundryPolygons.Add(BoundryPolygon);
                itemList.Add("Lat: " + location.Latitude.ToString() + " Long: " + location.Longitude.ToString());

                boundaryPolygonsText.Text = String.Format("Boundary Polygons {0}", itemList.Count);
                arrayAdapter              = new ArrayAdapter <string>(Activity, Resource.Layout.list_item, itemList);
                bpListView.Adapter        = arrayAdapter;
                bpListView.ItemLongClick += Adapter_ItemSwipe;
                int listViewMinimumHeight = 25 * _BoundryPolygons.Count();
                bpListView.SetMinimumHeight(listViewMinimumHeight);
            }
        }
 public void OnLocationChanged (Location location)
 {
     var locationText = FindViewById<TextView> (Resource.Id.locationTextView);
  
     locationText.Text = String.Format ("Latitude = {0}, Longitude = {1}", location.Latitude, location.Longitude);
  
     // demo geocoder
  
     new Thread (new ThreadStart (() => {
         var geocdr = new Geocoder (this);
      
         var addresses = geocdr.GetFromLocation (location.Latitude, location.Longitude, 5);
      
         //var addresses = geocdr.GetFromLocationName("Harvard University", 5);
      
         RunOnUiThread (() => {
             var addrText = FindViewById<TextView> (Resource.Id.addressTextView);
  
             addresses.ToList ().ForEach ((addr) => {
                 addrText.Append (addr.ToString () + "\r\n\r\n");
             });
         });
      
     })).Start ();
 }
Ejemplo n.º 6
0
 public void OnLocationChanged(Android.Locations.Location location)
 {
     if (LocationChangedCallback != null)
     {
         LocationChangedCallback(location);
     }
 }
Ejemplo n.º 7
0
		public async void OnLocationChanged(Location location)
		{
			_currentLocation = location;

			if (_currentLocation == null) {
				state.Text = "Location is not available";

			} else {
				Log.Debug (TAG, string.Format ("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude));
				//Please use Emulator API23. Geocoder is not available on Emulator API19, got bug
				address = await ReverseGeocodeCurrentLocation ();

				if (address == null) {
					state.Text = "String: No Address";
				} else {
					state.Text = address.GetAddressLine (address.MaxAddressLineIndex - 1);
					int complete = await ccm.HTMLDownload (address.GetAddressLine (address.MaxAddressLineIndex - 1));
					if (complete == 1) {
						int locationIndex = GetNearestLocationIndex ();
						UpdateUI (locationIndex);
					} else {
						UpdateUI (999);
					}
				}
			}
		}
            public void OnLocationChanged(Android.Locations.Location location)
            {
                if (location.Provider != ActiveProvider)
                {
                    if (ActiveProvider != null && Manager.IsProviderEnabled(ActiveProvider))
                    {
                        var lapsed = ToTime(location.Time) - ToTime(LatestLocation.Time);

                        if (Manager.GetProvider(location.Provider).Accuracy > Manager.GetProvider(ActiveProvider).Accuracy &&
                            lapsed < ReportIntervals.Add(ReportIntervals))
                        {
                            location.Dispose();
                            return;
                        }
                    }

                    ActiveProvider = location.Provider;
                }

                Interlocked.Exchange(ref LatestLocation, location)?.Dispose();

                var position = location.ToGeoPosition();

                PositionChanged.RaiseOn(Zebble.Thread.Pool, position);
            }
Ejemplo n.º 9
0
        /// <summary>
        /// OnLocationChanged
        /// </summary>
        /// <param name="location"></param>
        public void OnLocationChanged(Location location)
        {
            double lat = location.Latitude;
            double lon = location.Longitude;

            _lat.Text = lat.ToString();
            _lon.Text = lon.ToString();

            var currentloc = new GeoCoordinate(lat, lon);

            foreach (var v in _storeLocations)
            {
                var storelocation = new GeoCoordinate(v.Value.Latitude, v.Value.Longitude);
                var distance = currentloc.GetDistanceTo(storelocation);
                _distanceTo.Text = distance.ToString();

                Context context = this;
                Android.Content.Res.Resources res = context.Resources;
                string minRadius = res.GetString(Resource.String.minRadiusinMeters);

                if (distance < Convert.ToInt16(minRadius))
                {
                    new AlertDialog.Builder(this)
                     .SetMessage("Hey you are near to store, happy shopping!..")
                     .SetNeutralButton("Ok", delegate { }).Show();
                }
                return;
            }
        }
Ejemplo n.º 10
0
        public override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            LocHandler = new LocationHandler(Activity.GetSystemService(Activity.LocationService) as LocationManager);
            LocHandler.LocationRequest += (sender, args) =>
            {
                if (args == LocationHandler.messageType.LOCATION)
                {
                    // sets the location initially
                    var loc = (Location)sender;
                    if (followPosition)
                    {
                        lastPosition = loc;
                        SetLocation(loc.Latitude, loc.Longitude);
                    }
                }
                else if (args == LocationHandler.messageType.DISABLED)
                {
                    Toast.MakeText(Activity, Resource.String.ENABLE_GPS, ToastLength.Long).Show();
                }
                else if (args == LocationHandler.messageType.ENABLED)
                {
                    Log.Debug("GPSPROVIDER", "Enabled");
                }
            };

            // initializes the LocationHandler and fires an event if any porblems occur
            LocHandler.Init();
        }
Ejemplo n.º 11
0
        public async Task <GeoLocation> GetCurrentLocation()
        {
            if (_curLocation == null)
            {
                _locationRecieved = new TaskCompletionSource <Android.Locations.Location>();

                Criteria locationCriteria = new Criteria();

                locationCriteria.Accuracy         = Accuracy.Coarse;
                locationCriteria.PowerRequirement = Power.Low;

                string locationProvider = Manager.GetBestProvider(locationCriteria, true);

                if (locationProvider != null && Manager.IsProviderEnabled(locationProvider))
                {
                    Manager.RequestLocationUpdates(locationProvider, 2000, 1, Activity);

                    Android.Locations.Location loc = await _locationRecieved.Task.TimeoutAfter(1000);

                    if (loc != null)
                    {
                        _curLocation = new GeoLocation(loc.Latitude, loc.Longitude);
                    }
                }
            }

            return(_curLocation);
        }
Ejemplo n.º 12
0
        //called whenever location is changed
        public void OnLocationChanged(Android.Locations.Location location)
        {
            //own location is updated
            ownloc = new LatLng(location.Latitude, location.Longitude);

            //When location is initialized an gps position is found, init markers and map
            if (firstloc == true)
            {
                InitMapFragment();
                InitMarkers();
                ZoomOnLoc();
                firstloc = false;
            }

            //loc to string
            ownlocstring = location.Latitude.ToString().Replace(",", ".") + "," + location.Longitude.ToString().Replace(",", ".");

            //publish own location in a thread to prevent stutters
            Thread PublishMQTT = new Thread(() => MQTTPublish(ownlocstring));

            PublishMQTT.Start();

            //truck needs to update its route and duration when its location changes
            if (truckbool == true)
            {
                foreach (PartnerVehicle aPartnerVehicle in partnerlist)
                {
                    if (aPartnerVehicle.getid() == id)
                    {
                        Thread mapAPICall2 = new Thread(() => mapAPICall(aPartnerVehicle));
                        mapAPICall2.Start();
                    }
                }
            }
        }
        // get My Location
        async void GetMyLocation()
        {
            if (!CheckLocationPermission())
            {
                return;
            }

            mLastLocation = await LocationClient.GetLastLocationAsync();

            if (mLastLocation != null)
            {
                LatLng myposition = new LatLng(mLastLocation.Latitude, mLastLocation.Longitude);
                mainMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(myposition, 20));

                // get Address
                Address address = await ReverseGeocodeCurrentLocation(myposition);

                DisplayAddress(address);

                MarkerOptions options = new MarkerOptions()

                                        .SetPosition(myposition)
                                        .SetIcon(null)
                                        //  .SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.greenmarker))
                                        .SetTitle(Governorate)
                                        .SetSnippet(_addressText)
                                        .Draggable(true);

                mainMap.AddMarker(options);
            }
        }
Ejemplo n.º 14
0
 public void OnLocationChanged(Location location)
 {
     if (location != null)
     {
         LocationChanged?.Invoke(location.Latitude, location.Longitude);
     }
 }
Ejemplo n.º 15
0
		public static JsonArray GetPoiInformation(Location userLocation, int numberOfPlaces)
		{
			if (userLocation == null)
				return null;

			var pois = new List<JsonObject> ();

			for (int i = 0; i < numberOfPlaces; i++)
			{
				var loc = GetRandomLatLonNearby (userLocation.Latitude, userLocation.Longitude);

				var p = new Dictionary<string, JsonValue>(){
					{ "id", i.ToString() },
					{ "name", "POI#" + i.ToString() },
					{ "description", "This is the description of POI#" + i.ToString() },
					{ "latitude", loc[0] },
					{ "longitude", loc[1] },
					{ "altitude", 100f }
				};


				pois.Add (new JsonObject (p.ToList()));
			}

			var vals = from p in pois select (JsonValue)p;

			return new JsonArray (vals);
		}
Ejemplo n.º 16
0
 public void OnResult(Android.Locations.Location location)
 {
     if (callback != null)
     {
         callback.Invoke((Android.Locations.Location)location);
     }
 }
Ejemplo n.º 17
0
 public bool StartTracking()
 {
     _currentLocation = null;
     _startTime = DateTime.UtcNow;
     _baseScreen.BackgroundService.LocationChanged += BackgroundService_LocationChanged;
     return _baseScreen.BackgroundService.StartLocationUpdates(true, 0, TimeSpan.Zero);
 }
Ejemplo n.º 18
0
        public async void OnLocationChanged(Android.Locations.Location location)
        {
            _currentLocation = location;
            if (_currentLocation == null)
            {
                _locationText.Text = "Unable to determine your location. Try again in a short while!";
            }
            else
            {
                hide.Visibility = ViewStates.Invisible;
                latitude        = _currentLocation.Latitude;
                longitude       = _currentLocation.Longitude;

                GetBicByUser();
                timer          = new Timer();
                timer.Interval = 6000;
                timer.Enabled  = true;
                timer.Elapsed += Timer_Elapsed;
                timer.Start();

                _locationText.Text = string.Format("Latitude: {0:f6}, Longitude: {1:f6}", _currentLocation.Latitude, _currentLocation.Longitude);
                Address address = await ReverseGeocodeCurrentLocation();

                DisplayAddress(address);
            }
        }
Ejemplo n.º 19
0
		public async void OnLocationChanged (Location location)
		{
			_currentLocation = location;
			if (_currentLocation == null) {
				_locationText.Text = "Unable to determine your location. Try again in a short while.";
				Insights.Track ("UnableToDetermineLocation");
			} else {
				_locationText.Text = string.Format ("{0:f6},{1:f6}", _currentLocation.Latitude, _currentLocation.Longitude);
				Address address = await ReverseGeocodeCurrentLocation ();
				DisplayAddress (address);
			}
			var apiCall = new ApiCall ();
			await apiCall.Post<TestDriveLog, List<TestDriveLog>> ("test-drive-log", new TestDriveLog () {
				test_drive_id = 1,
				latitude = _currentLocation.Latitude,
				longitude = _currentLocation.Longitude
			}).ContinueWith (t => {
				var tData = new Dictionary<string, string>{
					{"Status", t.Status.ToString()},
					{"Task", t.ToString()},
				};
				if(t.IsCanceled) {
					Insights.Track ("ApiCallCanceled", tData);
				}
				else if(t.IsFaulted) {
					Insights.Track ("ApiCallFaulted", tData);
				}
				else if(t.IsCompleted) {
					Insights.Track ("ApiCallCompleted", tData);
				}
				else {
					Insights.Track ("ApiCallUnknown", tData);
				}
			});
		}
        //Interface :  ILocationListener
        public void OnLocationChanged(Location location)
        {
            Double lat, lng;

            lat = location.Latitude;
            lng = location.Longitude;

            if (markerLocation == null)
            {
                markerLocation = new MarkerOptions();
                markerLocation.SetPosition(new LatLng(lat, lng));
                markerLocation.SetTitle("Mi Posicion");
                map.AddMarker(markerLocation);
            }
            else
            {
                markerLocation.SetPosition(new LatLng(lat, lng));
            }



            CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
            builder.Target(new LatLng(lat, lng));


            CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngZoom(new LatLng(lat, lng), 15);

            map.MoveCamera(cameraUpdate);
        }
Ejemplo n.º 21
0
 public void OnLocationChanged(Location location)
 {
     // Set CurrentLocation on POIListViewAdapter when a location change is received
       _adapter.CurrentLocation = location;
       // call NotifyDataSetChange() to cause the ListView to be refreshed
       _adapter.NotifyDataSetChanged();
 }
Ejemplo n.º 22
0
        public void OnLocationChanged(Location location)
        {
            if (locationInitialised)
            {
                _currentLocation = location;
                if (_currentLocation == null)
                {
                    //_locationText.Text = "Unable to determine your location.";
                    Toast.MakeText(this, "Unable to determine your location.", ToastLength.Short).Show();
                }
                else
                {       //turn off gps for this process to complete **process moved to search
                    Toast.MakeText(this, "GeoManager GPS Position: " + _currentLocation.Latitude + " , " + _currentLocation.Longitude, ToastLength.Long).Show();

                    ////               PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X,
                    ////location.Y, androidMap.Width, androidMap.Height);


                    //         ManagedProj4Projection gpsproj4 = new  ManagedProj4Projection();
                    //               string z = location.Altitude.ToString ();
                    //               gpsproj4.InternalProjectionParametersString = @"+proj=longlat +a=6378137.0000 +rf=298.2572221010000 +units=m +nadgrids=@null +no_defs";
                    //               gpsproj4.ExternalProjectionParametersString = @"+proj=utm +zone=37 +south +ellps=clrk80 +towgs84=-160,-6,-302,0,0,0,0 +units=m +no_defs";//ManagedProj4Projection.GetEpsgParametersString(21037);
                    //               gpsproj4.Open();
                    //               Vertex gpspoint  = gpsproj4 .ConvertToExternalProjection   (location .Latitude , location .Longitude );
                    //               gpsproj4.Close();
                }
            }
        }
Ejemplo n.º 23
0
 public void OnLocationChanged(Android.Locations.Location location)
 {
     if (locationChanged != null)
     {
         locationChanged(this, location.GetCoordinates());
     }
 }
Ejemplo n.º 24
0
        public void OnLocationChanged(Android.Locations.Location androidLocation)
        {
            if (androidLocation == null)
            {
                MvxTrace.Trace("Android: Null location seen");
                return;
            }

            if (androidLocation.Latitude == double.MaxValue ||
                androidLocation.Longitude == double.MaxValue)
            {
                MvxTrace.Trace("Android: Invalid location seen");
                return;
            }

            MvxGeoLocation location;

            try
            {
                location = CreateLocation(androidLocation);
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (Exception exception)
            {
                MvxTrace.Trace("Android: Exception seen in converting location " + exception.ToLongString());
                return;
            }

            SendLocation(location);
        }
Ejemplo n.º 25
0
        public void OnLocationChanged(Location location)
        {
            //if location has changed
            if (location != null)
            {
                latitudine  = location.Latitude;
                longitudine = location.Longitude;
                if (latitudine > 0 && longitudine > 0)
                {
                    //if the map already exists
                    if (eMap != null)
                    {
                        latlng = new LatLng(latitudine, longitudine);
                        //If already exists a marker, delete it
                        if (marker1 != null)
                        {
                            marker1.Remove();
                            marker1 = null;
                        }

                        marker1 = eMap.AddMarker(new MarkerOptions().SetPosition(latlng).SetTitle("My location")
                                                 .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueCyan)));
                        //eMap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(latlng2, 15.7F));
                    }
                    //Toast.MakeText(ApplicationContext, string.Format("UPDATE LOCATION lat => {0} long => {1}", location.Latitude, location.Longitude), ToastLength.Long).Show();
                }
            }
        } // end onLocationChanged
 public void OnLocationChanged(Android.Locations.Location location)
 {
     Log.Debug(tag, "Location changed");
     latitude.Text  = "Latitude: " + location.Latitude.ToString();
     longitude.Text = "Longitude: " + location.Longitude.ToString();
     provider.Text  = "Provider: " + location.Provider.ToString();
 }
Ejemplo n.º 27
0
        // ILocationListener is a way for the Service to subscribe for updates
        // from the System location Service

        public void OnLocationChanged(Android.Locations.Location location)
        {
            this.LocationChanged(this, new LocationChangedEventArgs(location));

            // This should be updating every time we request new location updates
            // both when teh app is in the background, and in the foreground
            //Log.Debug (logTag, String.Format ("Latitude is {0}", location.Latitude));
            //Log.Debug (logTag, String.Format ("Longitude is {0}", location.Longitude));
            //Log.Debug (logTag, String.Format ("Altitude is {0}", location.Altitude));
            //Log.Debug (logTag, String.Format ("Speed is {0}", location.Speed));
            //Log.Debug (logTag, String.Format ("Accuracy is {0}", location.Accuracy));
            //Log.Debug (logTag, String.Format ("Bearing is {0}", location.Bearing));
            _player.Start();

            try
            {
                using (WebClient client = new WebClient())
                {
                    //string json = string.Format("{{\"latitude\":{0},\"longitude\":{1},\"recorded_at\":'{2}'}}",
                    //    location.Latitude, location.Longitude, location.Time.ToString());
                    string json = string.Format("{{\"latitude\":{0},\"longitude\":{1}}}",
                                                location.Latitude, location.Longitude);
                    client.Headers[HttpRequestHeader.ContentType] = "application/json";
                    client.UploadString("http://www.quilkin.co.uk/Service1.svc/SaveLocation", json);
                    //client.UploadString("http://localhost:60080/Service1.svc/SaveLocation", json);
                    Log.Debug(logTag, "Posted to Web at " + DateTime.Now.ToShortTimeString());
                }
            }
            catch (Exception ex)
            {
                Log.Debug(logTag, "Web error: " + ex.Message);
            }
        }
Ejemplo n.º 28
0
        public DeviceLocation GetDeviceLocation()
        {
            IList <string> acceptableLocationProviders = manager.GetProviders(criteriaForLocationService, true);

            string _locationProvider = string.Empty;

            if (acceptableLocationProviders.Any())
            {
                _locationProvider = acceptableLocationProviders.First();
            }
            else
            {
                _locationProvider = String.Empty;
            }


            manager.RequestLocationUpdates(_locationProvider, 5, 10, this);
            Android.Locations.Location loc = manager.GetLastKnownLocation(_locationProvider);

            if (loc != null)
            {
                return(new DeviceLocation(loc.Latitude, loc.Longitude));
            }
            else
            {
                return(null);
            }
        }
            void Finish(Android.Locations.Location location)
            {
                var position = location.ToGeoPosition();

                OnFinished?.Invoke();
                CompletionSource.TrySetResult(position);
            }
Ejemplo n.º 30
0
        public void OnLocationChanged(Android.Locations.Location location)
        {
            curLatitudeValue = location.Latitude;
            curLatitude.Text = curLatitudeValue.ToString();
            curLongitudeValue = location.Longitude;
            curLongitude.Text = curLongitudeValue.ToString();

            //check the proximity to the offender location
            if (testLongitudeValue != 0.0 && testLatitudeValue != 0.0)
            {
                Location offenderLocation = new Location(Provider);
                offenderLocation.Longitude = testLongitudeValue;
                offenderLocation.Latitude = testLatitudeValue;
                float meters = location.DistanceTo(offenderLocation);

                if (!insideRadius && (meters < 100)) {
                    insideRadius = true;
                    SendNotification ();
                }
                else if (insideRadius && (meters > 100))
                {
                    insideRadius = false;
                }
                //Toast.MakeText(this, "Distance = " + meters.ToString() + " meters", ToastLength.Short).Show ();
            }
        }
Ejemplo n.º 31
0
        public void OnLocationChanged(Location location)
        {
            _builder.AppendLine(
                string.Format("Location updated, lat: {0}, long: {1}",
                              location.Latitude, location.Longitude)
            );

            try
            {
                Address address =
                    _geocoder
                        .GetFromLocation(location.Latitude, location.Longitude, 1)
                        .FirstOrDefault();

                if (address != null)
                {
                    _builder.AppendLine(" -> " + address.CountryName);
                }
            }
            catch (IOException io)
            {
                Android.Util.Log.Debug("LocationActivity", io.Message);
            }

            _locationText.Text = _builder.ToString();
        }
        public void OnLocationChanged(Location location)
        {
            if (IsEnd) {
                //(FindViewById<TextView>(Resource.Id.txtView)).Append(String.Format ("\r\n\r\nLatitude = {0}, Longitude = {1}", location.Latitude, location.Longitude));
                    }

                    longtitude = location.Longitude;
                    latitude = location.Latitude;
                    // demo geocoder
            //					Geocoder geocdr = new Geocoder(this);
            //
            //					System.Threading.Tasks.Task<IList<Address>> getAddressTask = geocdr.GetFromLocationAsync(location.Latitude, location.Longitude, 5);
            //					adrs = "Trying to reverse geo-code the latitude/longitude...";
            //
            //					IList<Address> addresses = await getAddressTask;
            //
            //					if (addresses.Any())
            //					{
            //						Address addr = addresses.First();
            //						adrs = addr.ToString();
            //					}
            //					else
            //					{
            //						Toast.MakeText(this, "Could not reverse geo-code the location", ToastLength.Short).Show();
            //					}
        }
Ejemplo n.º 33
0
        /// <summary>
        ///     Finishes the specified location.
        /// </summary>
        /// <param name="location">The location.</param>
        private void Finish(Android.Locations.Location location)
        {
            var p = new Position();

            if (location.HasAccuracy)
            {
                p.Accuracy = location.Accuracy;
            }
            if (location.HasAltitude)
            {
                p.Altitude = location.Altitude;
            }
            if (location.HasBearing)
            {
                p.Heading = location.Bearing;
            }
            if (location.HasSpeed)
            {
                p.Speed = location.Speed;
            }

            p.Longitude = location.Longitude;
            p.Latitude  = location.Latitude;
            p.Timestamp = LocationService.GetTimestamp(location);

            if (_finishedCallback != null)
            {
                _finishedCallback();
            }

            _completionSource.TrySetResult(p);
        }
            public void OnSuccess(Java.Lang.Object obj)
            {
                //var lastLocation = (Android.Locations.Location)obj;
                //gnssCompare.locationFromGoogleServices = lastLocation;

                Android.Locations.Location lastLocation = new Android.Locations.Location("hi");
                lastLocation.Altitude  = 1;
                lastLocation.Longitude = -5.9650355;
                lastLocation.Latitude  = 37.371402;



                this.gnssCompare.pvtMethod     = new WeightedLeastSquares();
                this.gnssCompare.constellation = new GalileoConstellation();
                //this.gnssCompare.locationFromGoogleServices = lastLocation;
                this.gnssCompare.locationFromGoogleServices = lastLocation;
                this.gnssCompare.pvtMethod.logFineLocation(lastLocation);


                Device.BeginInvokeOnMainThread(() =>
                {
                    CrossToastPopUp.Current.ShowToastMessage("OnSuccess" + this.gnssCompare.poseInitialized + " " + (this.gnssCompare.locationFromGoogleServices != null));
                });

                if (!this.gnssCompare.poseInitialized && this.gnssCompare.locationFromGoogleServices != null)
                {
                    this.gnssCompare.pose = Coordinates <Matrix> .globalGeodInstance(
                        this.gnssCompare.locationFromGoogleServices.Latitude,
                        this.gnssCompare.locationFromGoogleServices.Longitude,
                        this.gnssCompare.locationFromGoogleServices.Altitude);

                    this.gnssCompare.poseInitialized = true;
                }
            }
        private void Finish(Android.Locations.Location location)
        {
            var position = new Position();

            if (location.HasAccuracy)
            {
                position.Accuracy = location.Accuracy;
            }
            if (location.HasAltitude)
            {
                position.Altitude = location.Altitude;
            }
            if (location.HasBearing)
            {
                position.Heading = location.Bearing;
            }
            if (location.HasSpeed)
            {
                position.Speed = location.Speed;
            }

            position.Longitude = location.Longitude;
            position.Latitude  = location.Latitude;
            position.Timestamp = LocationService.GetTimestamp(location);

            _finishedCallback?.Invoke();

            _tcs.TrySetResult(OperationResult <Position> .AsSuccess(position));
        }
Ejemplo n.º 36
0
        public void OnLocationChanged(Android.Locations.Location location)
        {
            SettingsController.setCurrentLatitude(location.Latitude);
            SettingsController.setCurrentLongitude(location.Longitude);

            this.LocationChanged(this, new LocationChangedEventArgs(location));
        }
Ejemplo n.º 37
0
        void AddLocation_Click(object sender, EventArgs e)
        {
            GPSTracker GPSTracker = new GPSTracker();

            Android.Locations.Location location = GPSTracker.GPSCoordinate();
            if (!GPSTracker.isLocationGPSEnabled)
            {
                ShowSettingsAlert();
            }

            if (location == null)
            {
                MessageDialog messageDialog = new MessageDialog();
                messageDialog.SendToast("Unable to get location");
            }
            else
            {
                locationLinearlayout.Visibility = ViewStates.Visible;
                tvbLatitude.Text     = "Lat: " + location.Latitude.ToString();
                tvbLongitude.Text    = "Long: " + location.Longitude.ToString();
                accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString());
                _GPSCoordinates      = new GPSCoordinate()
                {
                    Latitude  = location.Latitude.ToString(),
                    Longitude = location.Longitude.ToString()
                };

                building.GPSCoordinates = _GPSCoordinates;
            }
        }
		void AnimateTo (Location location)
		{
			if (location != null) {
				_map.AnimateCamera (CameraUpdateFactory.NewLatLngZoom (
					new LatLng (location.Latitude, location.Longitude), _map.MaxZoomLevel - 6));
			}
		}
Ejemplo n.º 39
0
        private static MvxGeoLocation CreateLocation(Android.Locations.Location androidLocation)
        {
            var position = new MvxGeoLocation {
                Timestamp = androidLocation.Time.FromMillisecondsUnixTimeToUtc()
            };
            var coords = position.Coordinates;

            if (androidLocation.HasAltitude)
            {
                coords.Altitude = androidLocation.Altitude;
            }

            if (androidLocation.HasBearing)
            {
                coords.Heading = androidLocation.Bearing;
            }

            coords.Latitude  = androidLocation.Latitude;
            coords.Longitude = androidLocation.Longitude;
            if (androidLocation.HasSpeed)
            {
                coords.Speed = androidLocation.Speed;
            }
            if (androidLocation.HasAccuracy)
            {
                coords.Accuracy = androidLocation.Accuracy;
            }

            return(position);
        }
        float GetSquareDistance(Animal a, Android.Locations.Location l)
        {
            var latitude = Math.Pow(l.Latitude - a.latitude, 2);
            var altitude = Math.Pow(l.Altitude - a.altitude, 2);

            return(Convert.ToSingle(Math.Sqrt(latitude + altitude)));
        }
Ejemplo n.º 41
0
 public void OnLocationChanged(Android.Locations.Location location)
 {
     Log.Debug("tag", "Location changed");
     latitude  = location.Latitude.ToString();
     longitude = location.Longitude.ToString();
     provider  = location.Provider.ToString();
     OnMapReady(GMap);
 }
Ejemplo n.º 42
0
        static GPSCoordinate Convert(Location location)
        {
            GPSCoordinate result = location != null
                ? new GPSCoordinate(location.Latitude, location.Longitude, location.Time.ToDateTime().ToLocalTime())
                : new GPSCoordinate();

            return result;
        }
 public void onButtonClick(Location location)
 {
     //EditText Lat = FindViewById<EditText> (Resource.Id.
     //EditText Long = FindViewById<EditText> (Resource.Id.EditLong);
     //Lat.Text = location.Latitude.ToString ();
     //Long.Text = location.Longitude.ToString ();
     //EditText Address = FindViewById<EditText>(Resource.Id.EditAddress);
 }
        public void OnLocationChanged(Location location)
        {
            var currentLocation = new GeoPoint((int) (location.Latitude * 1e6), (int) (location.Longitude * 1e6));

            _mapOverlay.Add(currentLocation, "Current Location");

            _map.Controller.AnimateTo(currentLocation);
        }
Ejemplo n.º 45
0
 public void OnLocationChanged(Location location)
 {
     if (IsBetterLocation (location, lastKnownLocation)) {
         lastKnownLocation = location;
         if (geocoder != null)
             SerialScheduler.Factory.StartNew (RefreshGeocodedLocationName);
     }
 }
Ejemplo n.º 46
0
        public void HandleLocationChanged(object sender, LocationChangedEventArgs e)
        {
            Android.Locations.Location location = e.Location;
            Log.Debug(logTag, "Foreground updating");

            App.gpsLocationLat  = location.Latitude;
            App.gpsLocationLong = location.Longitude;
        }
Ejemplo n.º 47
0
        public void OnLocationChanged(Location location)
        {
            Availability availability;
            if (!_providerAvailabilities.TryGetValue(location.Provider, out availability))
                availability = Availability.Available;

            if (availability == Availability.Available)
                HandleLocationChanged(location);
        }
        public void OnLocationChanged(Location location)
        {
            Unsubscribe();

            if (location != null)
            {
                DoCallback(ToGeolocation(location));
            }
        }
 public void OnLocationChanged(Android.Locations.Location location)
 {
     /*string Text = String.Empty;
      *
      * Text += "Latitude: " + location.Latitude.ToString();
      * Text += ". Longitude: " + location.Longitude.ToString();
      * Text += ". Provider: " + location.Provider.ToString();
      * Toast.MakeText(this, Text, ToastLength.Long).Show();*/
 }
Ejemplo n.º 50
0
        public void OnLocationChanged ( Location location )
        {
            if (location == null) return;
            Log.Error (TAG, "Posisi :" + location.Altitude + ", " + location.Longitude + ", akurasi : " + location.Accuracy);

            if (!(location.Accuracy < 500.0f)) return;
            StopLocationUpdates ();
            SendLocationDataToWebsite (location);
        }
Ejemplo n.º 51
0
 private void BackgroundService_LocationChanged(object sender, BaseService.CoordinatesChangedEventArgs e)
 {
     if (_started)
     {
         DateTime current = e.Location.Time.ToDateTime();
         if (current >= _startTime)
             _currentLocation = e.Location;
     }
 }
Ejemplo n.º 52
0
 /// <summary>
 ///   Returns the distance in metres to the specified location.
 /// </summary>
 /// <param name="location"> </param>
 /// <returns> </returns>
 public static int GetDistanceTo(this Building building, Location location)
 {
     if ((building == null) || (location == null))
     {
         return 0;
     }
     var buildingLocation = new Location("me") {Latitude = building.Latitude, Longitude = building.Longitude};
     return (int) buildingLocation.DistanceTo(location);
 }
Ejemplo n.º 53
0
        public void OnLocationChanged(Location location)
        {
            var geocoder = new Geocoder (this, Java.Util.Locale.Default);
            var addresses = geocoder.GetFromLocation (location.Latitude, location.Longitude, 1);

            if (addresses.Count > 0)
            {
                app.UserCity.OnNext(addresses [0].Locality);
            }
        }
Ejemplo n.º 54
0
 public void OnLocationChanged(Location location)
 {
     currentLocation = location;
     if(currentLocation != null)
     {
         gpsLatitude.Text = currentLocation.Latitude.ToString();
         gpsLongitude.Text = currentLocation.Longitude.ToString();
         gpsSpeed.Text = currentLocation.Speed.ToString();
     }
 }
		public void OnLocationChanged (Location location)
		{
			currentLocation = location;
			if (currentLocation == null) {
				Toast.MakeText (this, "Unable to determine your location.", ToastLength.Short);
			} else {
				gps_coordinates.Text = String.Format ("{0},{1}",
					currentLocation.Latitude, currentLocation.Longitude);
			}
		}
Ejemplo n.º 56
0
		public void OnConnected (Bundle connectionHint)
		{
			mLastLocation = LocationServices.FusedLocationApi.GetLastLocation (mGoogleApiClient);
			if (mLastLocation != null) {
				mLatitudeText.Text = mLastLocation.Latitude.ToString ();
				mLongitudeText.Text = mLastLocation.Longitude.ToString ();
			} else {
				Toast.MakeText (this, Resource.String.no_location_detected, ToastLength.Long).Show ();
			}
		}
        public void OnLocationChanged(Location location)
        {
            if (location != null)
                lastKnownLocation = location;

            if (location.HasAltitude)
                architectView.SetLocation (location.Latitude, location.Longitude, location.Altitude, location.HasAccuracy ? location.Accuracy : 1000);
            else
                architectView.SetLocation(location.Latitude, location.Longitude, location.HasAccuracy ? location.Accuracy : 1000);
        }
        public Position GetCurrentPosition()
        {
            _currentLocation = _locationManager.GetLastKnownLocation(_locationProvider);

            if (_currentLocation != null)
            {
                pos = new Position(_currentLocation.Latitude, _currentLocation.Longitude);
            }

            return pos;
        }
Ejemplo n.º 59
0
        public void OnLocationChanged(Location location)
        {
            var referenceHub = new Hub
            {
                Lat = location.Latitude,
                Lng = location.Longitude,
                Radius = 1 * 1000
            };

            this.hubAdapter.RefreshHubs(referenceHub, 5);
        }
        private async void SearchYelp(Location location)
        {
            var searchString = @"https://api.yelp.com/v2/search?term=food&ll=" + location.Latitude + "," + location.Longitude + @"&sort=1&limit=5";

            var restaurantList = await YelpData.PerformSearch(searchString);

            var intent = new Intent(this, typeof(YelpSearchResultActivity));
            intent.PutExtra("restaurantList", (string)restaurantList);
            intent.PutExtra("searchResultHeader", "Nearest Restaurants to You");
            StartActivity(intent);
        }