コード例 #1
0
        private async Task <bool> LocationToLatLng()
        {
            try
            {
                var geo           = new Geocoder(this);
                var sourceAddress = await geo.GetFromLocationNameAsync(mCurrentPostionString, 1);

                sourceAddress.ToList().ForEach((addr) =>
                {
                    mLatLngSource = new LatLng(addr.Latitude, addr.Longitude);
                });

                var destAddress = await geo.GetFromLocationNameAsync(mClosestStopString, 1);

                destAddress.ToList().ForEach((addr) =>
                {
                    mLatLngDestination = new LatLng(addr.Latitude, addr.Longitude);
                });

                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #2
0
        async Task <bool> FnLocationToLatLng()
        {
            try
            {
                var geo = new Geocoder(this);
                //var sourceAddress = await geo.GetFromLocationNameAsync(Constants.strSourceLocation, 1);
                var sourceAddress = await geo.GetFromLocationNameAsync(Constants.strSourceLocation, 1);

                sourceAddress.ToList().ForEach((addr) =>
                {
                    latLngSource = new LatLng(addr.Latitude, addr.Longitude);
                });

                //var destAddress = await geo.GetFromLocationNameAsync(Constants.strDestinationLocation, 1);
                var destAddress = await geo.GetFromLocationNameAsync(Constants.strDestinationLocation, 1);

                destAddress.ToList().ForEach((addr) =>
                {
                    latLngDestination = new LatLng(addr.Latitude, addr.Longitude);
                });

                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #3
0
        async public void GetMarkOnMapForNameOfStreet(string addr)
        {
            geo = new Geocoder(this);

            var add = addr;

            var approximateLocation = await geo.GetFromLocationNameAsync(add, 1);

            //Toast.MakeText(this, approximateLocation[0].Latitude + "," + approximateLocation[0].Longitude,ToastLength.Long); // nece da stampa ne znam sto
            LatLng latLng = new LatLng(approximateLocation[0].Latitude, approximateLocation[0].Longitude);

            if (approximateLocation[0].CountryName == "Србија")
            {                                                                        //da zumira kameru gde mi je marker
                CameraUpdate camera = CameraUpdateFactory.NewLatLngZoom(latLng, 15); // apdejtovace se kamera na mesto gde je latLng i uveca ce se puta 10
                gmap.MoveCamera(camera);
                //da setuje marker
                MarkerOptions options = new MarkerOptions().SetPosition(latLng).SetTitle("Nasao sam te.").SetSnippet(addr);

                gmap.AddMarker(options);


                //proveri kao trebalo bi da vrati neki float pitanje sta
                //Location start = new Location("starting point");
                //Location end = new Location("ending point");

                //float bearing = start.BearingTo(end);
            }
        }
コード例 #4
0
        public static async Task <double[]> GetCoordonateFromName(string address)
        {
            var location = new Geocoder(Application.Context);

            IList <Address> resultServer = new List <Address>();

            try
            {
                resultServer = await location.GetFromLocationNameAsync(address, 1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            var firstOrDefault = resultServer.FirstOrDefault();

            if (firstOrDefault != null)
            {
                return resultServer.Count > 0
                    ? new[]
                       {
                           firstOrDefault.Latitude,
                           firstOrDefault.Longitude
                       }
            }
            : default(double[]);

            location.Dispose();
            return(default(double[]));
        }
コード例 #5
0
ファイル: PlaceBLL.cs プロジェクト: lester-s/CheckDatPlace
        async internal Task <List <Address> > GetLocationFromAddress(Context context, int maxResult, params string[] address)
        {
            List <Address> result = new List <Address>();

            foreach (var ad in address)
            {
                if (string.IsNullOrWhiteSpace(ad))
                {
                    continue;
                }
                var geo = new Geocoder(context);
                try
                {
                    var addresses = await geo.GetFromLocationNameAsync(ad, maxResult);

                    result.AddRange(addresses);
                }
                catch (Exception)
                {
                    Toast.MakeText(context, "Cannot recover addresses !", ToastLength.Short).Show();
                }
            }

            return(result);
        }
コード例 #6
0
        private async Task <LatLng> GetLocationFromAddress(string strAddress)
        {
            if (string.IsNullOrEmpty(strAddress))
            {
                return(null);
            }

#pragma warning disable 618
            var locale = (int)Build.VERSION.SdkInt < 25 ? Resources?.Configuration?.Locale : Resources?.Configuration?.Locales.Get(0) ?? Resources?.Configuration?.Locale;
#pragma warning restore 618
            Geocoder coder = new Geocoder(this, locale);

            try
            {
                var address = await coder.GetFromLocationNameAsync(strAddress, 2);

                switch (address)
                {
                case null:
                    return(null !);
                }

                Address location = address[0];
                Lat = location.Latitude;
                Lng = location.Longitude;

                LatLng p1 = new LatLng(Lat, Lng);
                return(p1);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(null !);
            }
        }
コード例 #7
0
        private async Task <LatLng> GetLocationFromAddress(string strAddress)
        {
            #pragma warning disable 618
            var locale = (int)Build.VERSION.SdkInt < 25 ? MainContext.Resources?.Configuration.Locale : MainContext.Resources?.Configuration.Locales.Get(0) ?? MainContext.Resources?.Configuration.Locale;
            #pragma warning restore 618
            Geocoder coder = new Geocoder(MainContext, locale);

            try
            {
                var address = await coder.GetFromLocationNameAsync(strAddress, 2);

                if (address == null)
                {
                    return(null !);
                }

                Address location = address[0];
                var     lat      = location.Latitude;
                var     lng      = location.Longitude;

                LatLng p1 = new LatLng(lat, lng);

                return(p1);
            }
            catch (Exception e)
            {
                Methods.DisplayReportResultTrack(e);
                return(null !);
            }
        }
コード例 #8
0
        private async void ShowPOI(object sender, GoogleMap.MapLongClickEventArgs e)
        {
            foreach (var point in pointsOfInterest)
            {
                point.Remove();
            }
            pointsOfInterest.Clear();

            LatLngBounds bounds = e.Point.GetBoundingBox(8000);

            var geocoder = new Geocoder(this);
            var results  = await geocoder.GetFromLocationNameAsync("Starbucks", 5,
                                                                   bounds.Southwest.Latitude, bounds.Southwest.Longitude,
                                                                   bounds.Northeast.Latitude, bounds.Northeast.Longitude);

            foreach (var result in results)
            {
                var markerOptions = new MarkerOptions()
                                    .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueCyan))
                                    .SetPosition(new LatLng(result.Latitude, result.Longitude))
                                    .SetTitle(result.FeatureName)
                                    .SetSnippet(GetAdress(result));

                pointsOfInterest.Add(map.AddMarker(markerOptions));
            }
        }
コード例 #9
0
        public static async Task <IList <double[]> > GetCoordonateFromName(IList <string> address)
        {
            var location = new Geocoder(Application.Context);

            IList <double[]> result = new List <double[]>();

            foreach (var item in address)
            {
                IList <Address> resultServer = new List <Address>();

                try
                {
                    resultServer = await location.GetFromLocationNameAsync(item, 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                if (resultServer.Count <= 0)
                {
                    continue;
                }
                var firstOrDefault = resultServer.FirstOrDefault();
                if (firstOrDefault != null)
                {
                    result.Add(new[] { firstOrDefault.Latitude, firstOrDefault.Longitude });
                }
            }

            location.Dispose();
            return(result);
        }
コード例 #10
0
        private async Task <LatLng> GetLocationFromAddress(string strAddress)
        {
            var      locale = MainContext.Resources.Configuration.Locale;
            Geocoder coder  = new Geocoder(MainContext, locale);

            try
            {
                var address = await coder.GetFromLocationNameAsync(strAddress, 2);

                if (address == null)
                {
                    return(null);
                }

                Address location = address[0];
                var     lat      = location.Latitude;
                var     lng      = location.Longitude;

                LatLng p1 = new LatLng(lat, lng);

                return(p1);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(null);
            }
        }
コード例 #11
0
ファイル: UiServices.cs プロジェクト: antukidem/Uride
        //=========================================================================================================================

        public static async Task <LatLng> convertNameToLatLngLocation(Context ctx, string LocationName)
        {
            var    geo    = new Geocoder(ctx);
            LatLng latLng = new LatLng(0, 0);

            try
            {
                var address = await geo.GetFromLocationNameAsync(LocationName, 1);

                address.ToList().ForEach((addr) =>
                {
                    latLng = new LatLng(addr.Latitude, addr.Longitude);
                });
                return(latLng);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(latLng);
            }
            finally
            {
                geo = null;
            }
        }
コード例 #12
0
ファイル: UiServices.cs プロジェクト: antukidem/Uride
        public async Task <Address> Geocode(Context ctx, string LocationName)
        {
            Geocoder        geocoder    = new Geocoder(ctx);
            IList <Address> addressList = await geocoder.GetFromLocationNameAsync(LocationName, 10);

            Address address = addressList.FirstOrDefault();

            return(address);
        }
コード例 #13
0
        public async Task <GeoLocation> GetLocationFromAddress(string address)
        {
            using (var geocoder = new Geocoder(Application.Context))
            {
                var foundlocation = await geocoder.GetFromLocationNameAsync(address, 1);

                var bestLocation = foundlocation.FirstOrDefault();
                return(new GeoLocation(bestLocation.Latitude, bestLocation.Longitude));
            }
        }
コード例 #14
0
        public async Task <Dictionary <string, double> > ReverseGeocoding(string address)
        {
            var geo = new Geocoder(_currentActivity.Activity);

            var result = await geo.GetFromLocationNameAsync(address, 1);

            return(new Dictionary <string, double>
            {
                { "Longitude", result[0].Longitude },
                { "Latitude", result[0].Latitude },
            });
        }
コード例 #15
0
        async public void Get()
        {
            var add = "Bulevar Nemanjica";
            var approximateLocation = await geo.GetFromLocationNameAsync(add, 1);

            //Toast.MakeText(this, approximateLocation[0].Latitude + "," + approximateLocation[0].Longitude,ToastLength.Long); // nece da stampa ne znam sto
            LatLng latLng = new LatLng(approximateLocation[0].Latitude, approximateLocation[0].Longitude);

            MarkerOptions options = new MarkerOptions().SetPosition(latLng).SetTitle("Nasao sam te").SetSnippet("I");

            gmap.AddMarker(options);
        }
コード例 #16
0
        public async Task <GeoAddress[]> GeocodeAddressAsync(string query, string currentLanguage, double?pickupLatitude, double?pickupLongitude, double searchRadiusInMeters)
        {
            // Do nothing with currentLanguage parameter since Android Geocoder
            // automatically gets the results using the system language
            var geocoder = new Geocoder(_androidGlobals.ApplicationContext);

            Position lowerLeft  = null;
            Position upperRight = null;

            if (!query.ToLowerInvariant().Contains("bounds=") &&
                pickupLatitude.HasValue && pickupLongitude.HasValue &&
                pickupLatitude.Value != 0 && pickupLatitude.Value != 0)
            {
                // Note that biasing only prefers results within the bounds; if more relevant results exist outside of these bounds, they may be included.
                var mapBounds = MapBounds.GetBoundsFromCenterAndRadius(pickupLatitude.Value, pickupLongitude.Value, searchRadiusInMeters, searchRadiusInMeters);
                lowerLeft = new Position {
                    Latitude = mapBounds.SouthBound, Longitude = mapBounds.WestBound
                };
                upperRight = new Position {
                    Latitude = mapBounds.NorthBound, Longitude = mapBounds.EastBound
                };
            }

            var locationsTask = lowerLeft != null && upperRight != null
                ? geocoder.GetFromLocationNameAsync(query.Replace("+", " "), 100, lowerLeft.Latitude, lowerLeft.Longitude, upperRight.Latitude, upperRight.Longitude)
                : geocoder.GetFromLocationNameAsync(query.Replace("+", " "), 100);

            try
            {
                var locations = await locationsTask;

                return(locations.Select(ConvertAddressToGeoAddress).ToArray());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex);
                return(new GeoAddress[0]);
            }
        }
コード例 #17
0
        public async Task <IEnumerable <Location> > GetLocationsAsync(string address)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            using (var geocoder = new Geocoder(Platform.AppContext))
            {
                var addressList = await geocoder.GetFromLocationNameAsync(address, 10);

                return(addressList?.ToLocations());
            }
        }
コード例 #18
0
        private async Task <LatLng> GetCoordinate(string place)
        {
            if (Geocoder.IsPresent)
            {
                Geocoder coder   = new Geocoder(this);
                var      results = await coder.GetFromLocationNameAsync(place, 1);

                if (results.Count >= 1)
                {
                    return(new LatLng(
                               results[0].Latitude,
                               results[0].Longitude));
                }
            }

            return(null);
        }
コード例 #19
0
        async Task RunAddressQuery()
        {
            var geoCoder  = new Geocoder(this);
            var addresses = await geoCoder.GetFromLocationNameAsync("Burbank Street", 50);

            if (addresses.Count > 0)
            {
                foreach (var address in addresses)
                {
                    MarkerOptions marker1 = new MarkerOptions();
                    marker1.SetPosition(new LatLng(address.Latitude, address.Longitude));
                    marker1.SetTitle("Hollywood");
                    marker1.InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen));
                    _map.AddMarker(marker1);
                }
            }
        }
コード例 #20
0
        async void MarkAddress(object sender, GoogleMap.MapLongClickEventArgs e)
        {
            markedAddresses.ForEach(m => m.Remove());
            markedAddresses.Clear();

            var geocoder = new Geocoder(this);
            var results  = await geocoder.GetFromLocationNameAsync(addressSearchTerm, 5);

            foreach (var result in results)
            {
                var markerOptions = new MarkerOptions()
                                    .SetIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueCyan))
                                    .SetPosition(new LatLng(result.Latitude, result.Longitude))
                                    .SetTitle(result.FeatureName)
                                    .SetSnippet(GetAddress(result));
                markedAddresses.Add(map.AddMarker(markerOptions));
            }
        }
コード例 #21
0
ファイル: PlaceBLL.cs プロジェクト: lester-s/CheckDatPlace
        async internal Task <List <Address> > GetLocationFromAddress(Context context, string address, int maxResult)
        {
            var geo = new Geocoder(context);
            //Android.Gms.Location.Places.
            List <Address> result = new List <Address>();

            try
            {
                var addresses = await geo.GetFromLocationNameAsync(address, maxResult);

                result = addresses.ToList <Address>();
            }
            catch (Exception)
            {
                Toast.MakeText(context, "Cannot recover addresses !", ToastLength.Short).Show();
            }
            return(result);
        }
コード例 #22
0
        /// <summary>
        /// Retrieve positions for address.
        /// </summary>
        /// <param name="address">Desired address</param>
        /// <param name="mapKey">Map Key required only on UWP</param>
        /// <returns>Positions of the desired address</returns>
        public async Task <IEnumerable <Position> > GetPositionsForAddressAsync(string address, string mapKey = null)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            using (var geocoder = new Geocoder(Application.Context))
            {
                var addressList = await geocoder.GetFromLocationNameAsync(address, 10);

                return(addressList.Select(p => new Position
                {
                    Latitude = p.Latitude,
                    Longitude = p.Longitude
                }));
            }
        }
コード例 #23
0
        private async void geocodeAddress(String a)
        {
            var g         = new Geocoder(this);
            var addresses = await g.GetFromLocationNameAsync(a, 1);


            double lat   = 0;
            double longi = 0;



            foreach (var temp in addresses)
            {
                lat   = temp.Latitude;
                longi = temp.Longitude;
            }

            addProximityAlert(lat, longi, a);
        }
コード例 #24
0
        public static async Task <double[]> GetCoordonateFromName(Context context, string address)
        {
            double[] result = { 0.0, 0.0 };
            try
            {
                var geocoder        = new Geocoder(context);
                var coordResultList = await geocoder.GetFromLocationNameAsync(address, 1);

                if (coordResultList.Count > 0)
                {
                    result = new[] { coordResultList.First().Latitude, coordResultList.First().Longitude }
                }
                ;
            }
            catch
            {
                return(new[] { 0.0, 0.0 });
            }

            return(result);
        }
コード例 #25
0
        private async Task <Address> PollGeocode(string address)
        {
            var geo     = new Geocoder(Activity);
            var timeout = TimeSpan.FromSeconds(15);

            var start = DateTime.Now;
            var task  = geo.GetFromLocationNameAsync(address, 1);

            while (!task.IsCompleted && DateTime.Now - start <= timeout)
            {
                await Task.Delay(100);
            }

            if (DateTime.Now - start > timeout)
            {
                return(null);
            }
            else
            {
                return(task.Result[0]);
            }
        }