Exemplo n.º 1
0
        /// <summary>
        ///     Adds the map fragment to layout and calls GetMapAsync.
        /// </summary>
        /// <remarks>
        ///     This helper will try to add and initialize a <c>MapFragment</c> to a container
        ///     widget on the form. An optional <c>IOnMapReadyCallback</c> object can be provided. If this
        ///     parameter is <c>null</c>, then the method will check to see if the <c>activity</c>
        ///     implements <c>IMapOnReadyCallback</c>. If it does, then the <c>activity</c>
        ///     will be used as the callback. Otherwise, the method will throw an
        ///     <c>ArgumentException</c>.
        /// </remarks>
        /// <returns>The map framgment to layout.</returns>
        /// <param name = "activity">Activity that will host the MapFragment. If </param>
        /// <param name = "resourceId">The <c>@+id</c> of the container widget that will hold the fragment.</param>
        /// <param name = "tag">A tag to assign the fragment.  Defaults to <c>map_frag>.</c></param>
        /// <param name = "onMapReadyCallback">
        ///     An <c>IOnMapReadyCallback</c> object. If this is null, then the helper will check to
        ///     see if the <c>activity</c> implements the interface and use that.
        /// </param>
        public static MapFragment AddMapFragmentToLayout(
            this AppCompatActivity activity,
            int resourceId,
            string tag = "map_frag",
            IOnMapReadyCallback onMapReadyCallback = null)
        {
            var options = new GoogleMapOptions();

            options.InvokeMapType(GoogleMap.MapTypeHybrid).InvokeCompassEnabled(true);

            MapFragment mapFrag = MapFragment.NewInstance(options);

            activity.FragmentManager.BeginTransaction().Add(resourceId, mapFrag, tag).Commit();

            if (onMapReadyCallback == null)
            {
                if (activity is IOnMapReadyCallback callback)
                {
                    mapFrag.GetMapAsync(callback);
                }
                else
                {
                    throw new ArgumentException(
                              "If the onMapReadyCallback is null, then the activity must implement the interface IOnMapReadyCallback.",
                              nameof(activity));
                }
            }
            else
            {
                mapFrag.GetMapAsync(onMapReadyCallback);
            }

            return(mapFrag);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            locationManager = (LocationManager)GetSystemService(Context.LocationService);
            SetContentView(Resource.Layout.activity_location);
            location_TxtView_Header      = FindViewById <TextView>(Resource.Id.location_TxtView_Header);
            location_TxtView_Header.Text = "تعیین موقعیت";
            location_Button_SetLocation  = FindViewById <Button>(Resource.Id.location_Button_SetLocation);
            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.Locatin_Fragment_map);
            MapIsActive Isactive    = new MapIsActive(this);

            location_Button_SetLocation.Click += delegate {
                //تعیین موقعیت توسط گوگل
                locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 1000, 1, this);
                mapFragment.GetMapAsync(this);
            };


            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);
                if (Isactive.IsGooglePlayServicesInstalled())
                {
                    mapFragment.GetMapAsync(this);
                }
                else
                {
                    Snackbar snackBar = Snackbar.Make(location_Button_SetLocation, "اجرای سرویس گوگل پلی به مشکل خورده است", Snackbar.LengthIndefinite).SetAction("تایید", (v) =>
                    {
                        Finish();
                    });

                    //set  action button text color
                    snackBar.SetActionTextColor(Android.Graphics.Color.Green);

                    snackBar.Show();
                }
            }
            else
            {
                // Log.Info(tag, "No location providers available");
                Snackbar snackBar = Snackbar.Make(location_Button_SetLocation, "مکان باب دستگاه مکانی را پیدا نکرد", Snackbar.LengthIndefinite).SetAction("تایید", (v) =>
                {
                    Finish();
                });

                //set  action button text color
                snackBar.SetActionTextColor(Android.Graphics.Color.Green);

                snackBar.Show();
            }
        }
Exemplo n.º 3
0
 public void OnLocationChanged(Location location)
 {
     latitude  = location.Latitude;
     longitude = location.Longitude;
     mapFragment.GetMapAsync(this);
     destinationMapFragment.GetMapAsync(this);
 }
Exemplo n.º 4
0
        // Every time *activity* is resumed, get hold of the location provider again if possible
        protected override void OnResume()
        {
            base.OnResume();

            locationManager = GetSystemService(Context.LocationService) as LocationManager; // initialise locationManager using system
            string provider = LocationManager.GpsProvider;                                  // choose (NetworkProvider, PassiveProvider,...) GPS for highest accuracy for addresses

            if (locationManager.IsProviderEnabled(provider))                                // check whether GPS provider actually available (e.g. device may not even have GPS)
            {
                locationManager.RequestLocationUpdates(provider, 5000, 1, this);            // keep getting, not just a single fix, at 5s intervals, if 1km or more moved - d'need ILocationListener interface
            }

            // Get initial location & display this in the map(s)
            var location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);

            // Get the last saved location - from cell towers (less accurate but more likely to have existed & been saved)
            latitude  = location.Latitude;
            longitude = location.Longitude;

            // could refactor this GetMapAsync stuff as used at least twice in class
            //            MyMap originMap = new MyMap();
            //            MyMap destinationMap = new MyMap();
            // MyMap originMap = new MyMap();       // would instantiate MyMap here, but couldn't get MyMap to work (qv)
            // MyMap destinationMap = new MyMap();

            originMapFragment.GetMapAsync(this);
            destinationMapFragment.GetMapAsync(this);
//            originMapFragment.GetMapAsync(originMap);   // the argument is the object in which callback OnMapReady is to be triggered
//            destinationMapFragment.GetMapAsync(destinationMap);
        }
Exemplo n.º 5
0
        protected override void OnCreate(Bundle bundle)
        {
            // Set our view from the "main" layout resource
            startPostingService();
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            // Initializing Elements
            Initialize();

            // Show the mapFragment
            // fm.BeginTransaction().Show(mapFrag);

            Android.App.FragmentTransaction t = FragmentManager.BeginTransaction();
            t.Show(mapFrag);
            t.Commit();

            // Checking Permissions
            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != (int)Permission.Granted)
            {
                RequestLocationPermission();
            }
            else
            {
                mapFrag.GetMapAsync(this);

                // Starting Location Service
                App.StartLocationService();
            }
        }
Exemplo n.º 6
0
 public void OnLocationChanged(Location location)
 {
     latitude  = location.Latitude;
     longitude = location.Longitude;
     frgMap.GetMapAsync(this);
     frgMapDest.GetMapAsync(this);
 }
Exemplo n.º 7
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var ignored = base.OnCreateView(inflater, container, savedInstanceState);

            var view = this.BindingInflate(Resource.Layout.fragment_map_view, null);

            var mapOptions = new GoogleMapOptions()
                             .InvokeTiltGesturesEnabled(false)
                             .InvokeCompassEnabled(true)
                             .InvokeRotateGesturesEnabled(true)
                             .InvokeUseViewLifecycleInFragment(false)
                             .InvokeZoomControlsEnabled(true)
                             .InvokeZoomGesturesEnabled(true)
                             .InvokeZOrderOnTop(true)
                             .InvokeCamera(new CameraPosition(new LatLng(54.180109f, 45.177947f), 14.0f, 0, 0));

            _mapFragment = MapFragment.NewInstance(mapOptions);
            var transaction = this.FragmentManager.BeginTransaction();

            transaction.Add(Resource.Id.content_frame, _mapFragment);
            transaction.Commit();

            _mapFragment.GetMapAsync(this);

            return(view);
        }
Exemplo n.º 8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            spinner = FindViewById <Spinner>(Resource.Id.spinner);
            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

            mapFragment.GetMapAsync(this);


            spinner.ItemSelected += Spinner_ItemSelected;


            locationManager = (LocationManager)GetSystemService(Context.LocationService);
            provider        = locationManager.GetBestProvider(new Criteria(), false);

            Location location = locationManager.GetLastKnownLocation(provider);

            if (location == null)
            {
                System.Diagnostics.Debug.WriteLine("No Location");
            }
        }
Exemplo n.º 9
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Map);

            // Create your application here
            ImageButton img_Back = FindViewById <ImageButton>(Resource.Id.imageButton_Back);

            img_Back.Click += Img_Back_Click;
            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

            mapFragment.GetMapAsync(this);
            locationManager = (LocationManager)GetSystemService(Context.LocationService);
            provider        = locationManager.GetBestProvider(new Criteria(), false);

            Location location = locationManager.GetLastKnownLocation(provider);

            if (location == null)
            {
                System.Diagnostics.Debug.WriteLine("ERROR");
            }
            //
            FnProcessOnMap();
        }
Exemplo n.º 10
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.LocationSelector);

            _mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment;

            if (_mapFragment == null)
            {
                GoogleMapOptions mapOptions = new GoogleMapOptions().InvokeMapType(GoogleMap.MapTypeNormal)
                                              .InvokeZoomControlsEnabled(true)
                                              .InvokeCompassEnabled(true);

                var fragTx = FragmentManager.BeginTransaction();
                _mapFragment = MapFragment.NewInstance(mapOptions);
                fragTx.Add(Resource.Id.map, _mapFragment, "map");
                fragTx.AddToBackStack("LocationSelectorMap");
                fragTx.Commit();
            }

            _mapFragment.GetMapAsync(this);

            _locationManager = GetSystemService(LocationService) as LocationManager;

            _saveButton = (Button)FindViewById(Resource.Id.saveButton);
            _saveButton.BringToFront();

            _saveButton.Click += delegate(object sender, EventArgs e) {
                this.ChargingLocation = _marker.Position;
                this.Finish();
            };
        }
Exemplo n.º 11
0
        //Marker _firstMarker;
        //Marker _secondMarker;
        //Marker _thirdMarker;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Maps);

            _pDialog = new ProgressDialog(this);
            _pDialog.Indeterminate = true;
            _pDialog.SetProgressStyle(ProgressDialogStyle.Spinner);
            _pDialog.SetMessage("Chargement...");
            _pDialog.SetCancelable(true);
            _pDialog.Show();

            _locationManager = GetSystemService(Context.LocationService) as LocationManager;

            _mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment;
            if (_mapFragment == null)
            {
                GoogleMapOptions mapOptions = new GoogleMapOptions()
                                              .InvokeMapType(GoogleMap.MapTypeSatellite)
                                              .InvokeZoomControlsEnabled(false)
                                              .InvokeCompassEnabled(true);

                FragmentTransaction fragTx = FragmentManager.BeginTransaction();
                _mapFragment = MapFragment.NewInstance(mapOptions);
                fragTx.Add(Resource.Id.map, _mapFragment, "map");
                fragTx.Commit();
            }
            _mapFragment.GetMapAsync(this);
        }
Exemplo n.º 12
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_task_list);

            s_order         = FindViewById <EditText>(Resource.Id.s_order);
            s_task          = FindViewById <EditText>(Resource.Id.s_task);
            btn_abort_order = FindViewById <Button>(Resource.Id.btn_abort_order);
            btn_performed   = FindViewById <Button>(Resource.Id.btn_performed);

            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.fragmentMap);

            mapFragment.GetMapAsync(this);

            s_order.Focusable     = false;
            s_order.LongClickable = false;
            s_task.Focusable      = false;
            s_task.LongClickable  = false;

            BuildLocationRequest();
            BuildLocationCallBack();

            fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);

            //ResetUser();
            fusedLocationProviderClient.RequestLocationUpdates(locationRequest,
                                                               locationCallback, Looper.MyLooper());
        }
Exemplo n.º 13
0
        private void SetUpMap()
        {
            _mapFragment = FragmentManager.FindFragmentByTag("map") as MapFragment;
            if (_mapFragment == null)
            {
                GoogleMapOptions mapOptions = new GoogleMapOptions()
                                              .InvokeMapType(GoogleMap.MapTypeHybrid)
                                              .InvokeZoomControlsEnabled(true)
                                              .InvokeCompassEnabled(true);

                FragmentTransaction fragTx = FragmentManager.BeginTransaction();
                _mapFragment = MapFragment.NewInstance(mapOptions);
                fragTx.Add(Resource.Id.map, _mapFragment, "map");
                fragTx.Commit();

                var mapReadyCallback = new MyOnMapReady();
                mapReadyCallback.MapReady += (sender, args) =>
                {
                    _gettingMap = false;
                    _map        = ((MyOnMapReady)sender).Map;

                    MoveCamera();
                };

                _gettingMap = true;

                _mapFragment.GetMapAsync(mapReadyCallback);
            }
        }
Exemplo n.º 14
0
        private void UpdateMapView()
        {
            var         mapReadyCallback = new LocalMapReady();
            List <Park> parks            = dataService.GetAllParks();

            mapReadyCallback.MapReady += (sender, args) =>
            {
                googleMap = (sender as LocalMapReady).Map;
                if (googleMap != null)
                {
                    foreach (var park in parks)
                    {
                        LatLng        location      = new LatLng(park.Lat, park.Long);
                        MarkerOptions markerOptions = new MarkerOptions();
                        markerOptions.SetPosition(location)
                        .SetTitle(park.Id.ToString())
                        .SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.tree16));

                        googleMap.AddMarker(markerOptions);
                    }

                    CameraUpdate cameraUpdate = CameraUpdateFactory.NewLatLngZoom(seattleLocation, 12);
                    googleMap.MoveCamera(cameraUpdate);
                    googleMap.MarkerClick += MapOnMarkerClick;
                }
            };

            mapFragment.GetMapAsync(mapReadyCallback);
        }
Exemplo n.º 15
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            this.RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Map);

            // Create your application here

            var surfaceOrientation = WindowManager.DefaultDisplay.Rotation;

            DisplayMetrics metrics = Resources.DisplayMetrics;

            bHeight = metrics.HeightPixels;

            if (surfaceOrientation == SurfaceOrientation.Rotation0 || surfaceOrientation == SurfaceOrientation.Rotation180)
            {
                bHeight = bHeight / 2;
            }
            bHeight = bHeight / 5;

            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

            mapFragment.GetMapAsync(this);

            InitializeLocationManager();
        }
Exemplo n.º 16
0
        // readonly GeofenceTriggerReceiver receiver = new GeofenceTriggerReceiver();

        // ---------------------------------------------------------------------------------------------------------------------------------- //

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Register our broadcast receiver
            //IntentFilter filter = new IntentFilter(GeofenceTriggerReceiver.IntentName);
            //RegisterReceiver(receiver, filter);

            // Find and load the map fragment
            mapFragment = FragmentManager.FindFragmentById(Resource.Id.map) as MapFragment;
            mapFragment.GetMapAsync(this);

            // After the map fragment is setup, use the GoogleApiClient.Builder fluid API to create and assign the apiClient field.
            if (GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this) == 0)
            {
                apiClient = new GoogleApiClient.Builder(this)
                            .AddConnectionCallbacks(this)
                            .AddOnConnectionFailedListener(this)
                            .AddApi(LocationServices.API)
                            .Build();
            }
        }
Exemplo n.º 17
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Map);

            var NavService = (NavigationService)SimpleIoc.Default.GetInstance <INavigationService>();
            var data       = NavService.GetAndRemoveParameter <List <double> >(Intent);

            if (data != null)
            {
                _mapFragment = FragmentManager.FindFragmentByTag("mapView") as MapFragment;
                if (_mapFragment == null)
                {
                    GoogleMapOptions mapOptions = new GoogleMapOptions()
                                                  .InvokeMapType(GoogleMap.MapTypeSatellite)
                                                  .InvokeZoomControlsEnabled(false)
                                                  .InvokeCompassEnabled(true);

                    FragmentTransaction fragTx = FragmentManager.BeginTransaction();
                    _mapFragment = MapFragment.NewInstance(mapOptions);
                    fragTx.Add(Resource.Id.mapView, _mapFragment, "mapView");
                    fragTx.Commit();
                }
                _mapFragment.GetMapAsync(this);


                ViewModel.Latitude  = data[0];
                ViewModel.Longitude = data[1];
            }

            CreateButtonBinding();
        }
Exemplo n.º 18
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();

            viewModel = new CoffeesViewModel();

            handler = new Handler();

            mapFragment = FragmentManager.FindFragmentById <MapFragment>(Resource.Id.map);

            addPin     = FindViewById <Button>(Resource.Id.button_add_pin);
            loadCoffee = FindViewById <Button>(Resource.Id.button_load_coffee);

            addPin.Enabled = loadCoffee.Enabled = false;

            mapFragment.GetMapAsync(this);

            addPin.Click += AddPin_Click;

            loadCoffee.Click += LoadCoffee_Click;
        }
Exemplo n.º 19
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);
                SetContentView(Resource.Layout.Passenger);
                Platform.Init(this, savedInstanceState);

                SetContentView(Resource.Layout.Map_layout);
                mapFragment = FragmentManager.FindFragmentByTag("passengermap") as MapFragment;
                if (mapFragment == null)
                {
                    GoogleMapOptions Options = new GoogleMapOptions()
                                               .InvokeRotateGesturesEnabled(true);
                    mapFragment = MapFragment.NewInstance(Options);
                    FragmentManager.BeginTransaction().Add(Resource.Id.map, mapFragment).Commit();
                }

                mapFragment.GetMapAsync(this);


                // Create your application here

                //AddMarker(await GetLocation());
            }
            catch (Exception)
            {
                Toast.MakeText(this, "Error occured", ToastLength.Long).Show();
                var intent = new Intent(this, typeof(MainPage));
                StartActivity(intent);
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Loads all of the needed elements
        /// </summary>
        /// <param name="savedInstanceState"></param>
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                base.OnCreate(savedInstanceState);

                Forms.Init(this, savedInstanceState);
                Xamarin.Essentials.Platform.Init(this, savedInstanceState);

                SetContentView(Resource.Layout.activity_main);

                finalOrder = new FinalOrder();

                fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);
                var location = fusedLocationProviderClient.GetLastLocationAsync();

                MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

                mapFragment.GetMapAsync(this);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here

            SetContentView(Resource.Layout.Locations);
            //initializing components
            set_location = FindViewById <Button>(Resource.Id.btn_set_1);
            //srch_button = FindViewById<Button>(Resource.Id.btn_srch_1);
            //srch_text = FindViewById<EditText>(Resource.Id.search_text);
            loader = FindViewById <LoadingView>(Resource.Id.loading_view);


            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            map1 = MapFragment.NewInstance();
            var ft = FragmentManager.BeginTransaction();

            ft.Add(Resource.Id.map_placeholder, map1).Commit();
            map1.GetMapAsync(this);

            imgsearchicon = (Button)FindViewById(Resource.Id.btnsearchimg);



            //setting on click events
            set_location.Click  += Set_location_Click;
            imgsearchicon.Click += Imgsearchicon_Click;
        }
Exemplo n.º 22
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_home);

            StaticMenu.id_page = 1;

            home_container = FindViewById <RelativeLayout>(Resource.Id.home_container);
            s_user         = FindViewById <TextView>(Resource.Id.s_user);

            s_user.Text = StaticUser.FirstName + " " + StaticUser.LastName;

            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.fragmentMap);

            mapFragment.GetMapAsync(this);

            BuildLocationRequest();
            BuildLocationCallBack();

            fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this);

            //ResetUser();
            fusedLocationProviderClient.RequestLocationUpdates(locationRequest,
                                                               locationCallback, Looper.MyLooper());

            //Task.Delay(1000).ContinueWith(t =>
            //{
            //	OnMapReady(_googleMap);
            //}, TaskScheduler.FromCurrentSynchronizationContext());
        }
Exemplo n.º 23
0
        // Initialize the map
        private void SetUpMap()
        {
            MapFragment mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);

            // Call GetMapAsync Method for map deployment in this activity
            mapFragment.GetMapAsync(this);
        }
Exemplo n.º 24
0
        protected override void OnResume()
        {
            base.OnResume();
            LocationManager = GetSystemService(LocationService) as LocationManager;
            const string provider = LocationManager.GpsProvider;

            try
            {
                if (LocationManager.IsProviderEnabled(provider))
                {
                    LocationManager.RequestLocationUpdates(provider, 500, 1, this);
                }
                var location = LocationManager.GetLastKnownLocation(LocationManager.NetworkProvider);
                if (location == null)
                {
                    App.LogOutLn("No Location received", GetType().Name);
                }
                else
                {
                    ViewModel.Latitude  = location.Latitude;
                    ViewModel.Longitude = location.Longitude;
                    ViewModel.Altitude  = location.Altitude;
                }
            }
            catch (Exception e)
            {
                App.LogOutLn(e.Message, GetType().Name);
            }
            MapFragment.GetMapAsync(this);
        }
Exemplo n.º 25
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            permissionHelper            = new MappingPermissionsHelper(this);
            getLocationPermissionsAsync = permissionHelper.CheckAndRequestPermissions();

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            mapFragment = FragmentManager.FindFragmentById(Resource.Id.map) as MapFragment;

            mapFragment.GetMapAsync(this);

            if (GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this) == 0)
            {
                apiClient = new GoogleApiClient.Builder(this)
                            .AddConnectionCallbacks(this)
                            .AddOnConnectionFailedListener(this)
                            .AddApi(LocationServices.API)
                            // Uncomment to test the error recovery code.
                            //.AddApi(PlusClass.API)
                            //.AddScope(PlusClass.ScopePlusLogin)
                            .Build();
            }
        }
Exemplo n.º 26
0
 public void OnLocationChanged(Location location)
 {
     ViewModel.Latitude  = location.Latitude;
     ViewModel.Longitude = location.Longitude;
     ViewModel.Altitude  = location.Altitude;
     MapFragment.GetMapAsync(this);
 }
Exemplo n.º 27
0
        public async void LoadMapLayout()
        {
            await System.Threading.Tasks.Task.Run(() =>
            {
                this.RunOnUiThread(() =>
                {
                    if (CheckConnection.IsInternet())
                    {
                        GetPlaceInfo(Name, LatLon.Split(",")[0], LatLon.Split(",")[1]);
                        foodiPlaces = GetPlaces();

                        placeAdapter = new FoodiPlaceAdapter(foodiPlaces, this);
                        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);
                        radLvFoodiPlaces.SetLayoutManager(linearLayoutManager);
                        radLvFoodiPlaces.SetAdapter(placeAdapter);

                        FoodiPlacesClickListenner foodiPlacesClickListenner = new FoodiPlacesClickListenner(this, placeAdapter);
                        radLvFoodiPlaces.AddItemClickListener(foodiPlacesClickListenner);
                        mapFragment = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
                        mapFragment.GetMapAsync(this);

                        DisplayCustomRatingBar(ratingBar);
                    }
                    else
                    {
                        Toast.MakeText(this, "No Internet Connected!", ToastLength.Long).Show();
                    }
                });
            });
        }
Exemplo n.º 28
0
        protected override void OnResume()
        {
            base.OnResume();

            locationManager = GetSystemService(Context.LocationService) as LocationManager;
            string provider = LocationManager.GpsProvider;

            if (locationManager.IsProviderEnabled(provider))
            {
                locationManager.RequestLocationUpdates(provider, 5000, 1, this);
            }

            var location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);

            latitude  = location.Latitude;
            longitude = location.Longitude;

            MyMap origin = new MyMap((obj) =>
            {
                this.originMap = obj;

                DrawOnMap(obj, new LatLng(latitude, longitude), "Точка 1");
            });
            MyMap destination = new MyMap((obj) =>
            {
                this.destinationMap = obj;

                DrawOnMap(obj, new LatLng(latitude, longitude), "Точка 2");
            });

            mapFragment.GetMapAsync(origin);
            destinationMapFragment.GetMapAsync(destination);
        }
Exemplo n.º 29
0
 private void SetUpMap()
 {
     if (mMap == null)
     {
         mapFragment.GetMapAsync(this);
     }
 }
        public override Android.Views.View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            // Use this to return your custom view for this Fragment
            var view = inflater.Inflate(Resource.Layout.DirectionMapLayout, container, false);

            Xamarin.Essentials.Platform.Init(this.Activity, savedInstanceState);

            //Initializing UI component
            GetDirection  = view.FindViewById <Button>(Resource.Id.getdirection);
            startLocation = view.FindViewById <TextView>(Resource.Id.materialTextView1);
            endLocation   = view.FindViewById <TextView>(Resource.Id.materialTextView2);
            radioStart    = view.FindViewById <RadioButton>(Resource.Id.radioButton1);
            radioEnd      = view.FindViewById <RadioButton>(Resource.Id.radioButton2);
            pin           = view.FindViewById <Button>(Resource.Id.pinid);

            //Initializing Click events
            startLocation.Click += StartLocation_Click;
            endLocation.Click   += EndLocation_Click;
            radioStart.Click    += RadioStart_Click;
            radioEnd.Click      += RadioEnd_Click;
            GetDirection.Click  += GetDirection_Click;

            //Setting up Map
            mapFragment = MapFragment.NewInstance();
            var ft = this.Activity.FragmentManager.BeginTransaction();

            ft.Add(Resource.Id.map_placeholder, mapFragment).CommitAllowingStateLoss();
            mapFragment.GetMapAsync(this);



            return(view);
        }
Exemplo n.º 31
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            txtTimeZone = FindViewById<TextView>(Resource.Id.txtUserAddress);

            //Check if location enabled
            if (!LocManager.IsProviderEnabled(LocationManager.GpsProvider))
            {
                ShowLocationDisableAlert();
            }

            //register location update service
            ERoadApp.Current.LocationServiceConnected += (object sender, ServiceConnectedEventArgs e) =>
            {
                ERoadApp.Current.LocationService.LocationChanged += HandleLocationChanged;
                ERoadApp.Current.LocationService.ProviderDisabled += HandleProviderDisabled;
                ERoadApp.Current.LocationService.ProviderEnabled += HandleProviderEnabled;
                ERoadApp.Current.LocationService.StatusChanged += HandleStatusChanged;
            };
            //Start service
            ERoadApp.StartLocationService();

            mapFrag = (MapFragment)FragmentManager.FindFragmentById(Resource.Id.map);
            mapFrag.GetMapAsync(this);

        }
Exemplo n.º 32
0
        private async void SetupMapIfNeeded()
        {
            if (_map == null && !_gettingMap)
            {
                // TODO À quoi sert cette variable ? On peut supprimer je pense.
                // a priori SetupMapIfNeeded peut-être appelé pluiseurs fois d'affilé, c'est pour prévenir ça
                _gettingMap = true;
                GoogleMapOptions mapOptions = new GoogleMapOptions()
                    .InvokeMapType(GoogleMap.MapTypeNormal)
                    //.InvokeZoomControlsEnabled(true)
                    //.InvokeMapToolbarEnabled(true)
                    .InvokeCompassEnabled(true)
                    .InvokeCamera(await GetStartingCameraPosition());

                _fragTx = FragmentManager.BeginTransaction();
                _mapFragment = MapFragmentExtended.NewInstance(mapOptions);
                _fragTx.Add(Resource.Id.map, _mapFragment, "map");
                _fragTx.Commit();
                _mapFragment.GetMapAsync(this);
            }

        }
Exemplo n.º 33
0
        // gets the reference to the map instance
        private void SetUpMapIfNeeded()
        {
            mapFragment = FragmentManager.FindFragmentById<MapFragment>(Resource.Id.map9879468784687);
            if (Map == null)
            {
                // registers an event to the handler (implements the callback concept)
                mapReadyCallback.MapReady += (sender, args) =>
                {
                    Map = ((GMapHandler)sender).Map;
                    SetUpMap();
                };

                mapFragment.GetMapAsync(mapReadyCallback);
            }
        }
Exemplo n.º 34
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);
            mf = FragmentManager.FindFragmentById (Resource.Id.map) as MapFragment;
            mf.GetMapAsync(this);
            //_shareButton = FindViewById<Button> (Resource.Id.sharebutton);
            //_shareButton.Click += delegate {};
        }
Exemplo n.º 35
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            SetContentView (Resource.Layout.Map);

            // Create a map fragment for gmaps
            mapFrag = MapFragment.NewInstance ();
            var tx = FragmentManager.BeginTransaction ();
            tx.Add (Resource.Id.MapLayout, mapFrag);
            tx.Commit ();

            // Grab a ref to the location manager
            var locMgr = GetSystemService (Context.LocationService) as LocationManager;
            // use GPS for location rather than wifi/3G
            var provider = LocationManager.GpsProvider;

            if (locMgr.IsProviderEnabled (provider))
            {
                // grab GPS loc every 5000ms for 1+ meter changes, alert this class' ILocationListener
                locMgr.RequestLocationUpdates (provider, 3000, 1, this);
            }
            else
            {
                // no GPS
                throw new Exception ("ded");
            }

            // wait like an idiot till map is ready
            mapFrag.GetMapAsync(this);
        }