Пример #1
0
        public IActionResult GetPinsFromBrand(string Brand, float Latitude, float Longitude)
        {
            var authorizeds = _authorizedRepository.GetAllByBrand(Brand);
            var search      = new SearchViewModel();

            foreach (var authorized in authorizeds)
            {
                //check if the distance of authorized is inside the avalaible radius
                var distance = Geolocation.CalculateDistance(Latitude, Longitude, Convert.ToDouble(authorized.Latitude), Convert.ToDouble(authorized.Longitude), 'K');
                if (distance > DISTANCE_LIMIT)
                {
                    continue;
                }

                var Authorized = new AuthorizedViewModel()
                {
                    Id                   = authorized.Id,
                    Nome                 = authorized.Nome,
                    Titulo               = authorized.Titulo,
                    Descricao            = authorized.Descricao,
                    Endereco             = authorized.Endereco,
                    Telefone             = authorized.Telefone,
                    Latitude             = Convert.ToDouble(authorized.Latitude),
                    Longitude            = Convert.ToDouble(authorized.Longitude),
                    Email                = authorized.Email,
                    HorarioFuncionamento = authorized.HorarioFuncionamento,
                    Servicos             = authorized.Servicos
                };
                var geometry = new GeometryViewModel
                {
                    Coordinates = new List <double> {
                        Convert.ToDouble(authorized.Longitude), Convert.ToDouble(authorized.Latitude)
                    }
                };
                var property = new PropertyViewModel
                {
                    Title = authorized.Nome
                };
                var feature = new FeaturesViewModel
                {
                    Geometry = geometry,
                    Property = property
                };

                search.Features.Add(feature);
                search.Authorizeds.Add(Authorized);
            }

            var jsonString = JsonSerializer.Serialize(search);

            return(Ok(jsonString));
        }
Пример #2
0
        /// <summary>
        /// Draws the marker.
        /// </summary>
        /// <param name="map2">Map2.</param>
        public void drawMarker(GoogleMap map2)
        {
            BitmapDescriptor mapIcon;

            if (map2 != null)
            {
                markerList = new List <Marker>();
                if (DataManager.Sucursales != null && DataManager.Sucursales.Count > 0)
                {
                    for (int i = 0; i < DataManager.Sucursales.Count; i++)
                    {
                        mapIcon = BitmapDescriptorFactory.FromResource(Resource.Drawable.liderubicacion);

                        if (DataManager.Sucursales[i].HasValidCoordinates())
                        {
                            string nombre = DataManager.Sucursales[i].name;

                            map2.MyLocationEnabled = true;
                            var           point      = new LatLng(DataManager.Sucursales[i].location.position.coordinates[1], DataManager.Sucursales[i].location.position.coordinates[0]);
                            MarkerOptions markerOpt1 = new MarkerOptions();
                            markerOpt1.SetPosition(point);
                            markerOpt1.SetTitle(nombre);
                            markerOpt1.SetIcon(mapIcon);
                            markerOpt1.SetSnippet(DataManager.Sucursales[i].location.address);
                            //map2.AddMarker(markerOpt1);
                            markerList.Add(map2.AddMarker(markerOpt1));


                            if (DataManager.actualLatitud != null)
                            {
                                var    lat      = DataManager.actualLatitud.Replace("\r", "").Replace(',', '.');
                                var    lon      = DataManager.actualLongitud.Replace("\r", "").Replace(',', '.');
                                var    latitude = double.Parse(lat, System.Globalization.CultureInfo.InvariantCulture);
                                var    longitud = double.Parse(lon, System.Globalization.CultureInfo.InvariantCulture);
                                double diff     = Geolocation.
                                                  CalculateDistance(latitude, longitud, DataManager.Sucursales[i].location.position.coordinates[1], DataManager.Sucursales[i].location.position.coordinates[0]);
                                DataManager.Sucursales[i].UserDistance    = diff;
                                DataManager.Sucursales[i].HasUserDistance = true;
                            }
                        }
                    }
                }
                else
                {
                    Toast.MakeText(Activity, "Lista de sucursales vacia", ToastLength.Short).Show();
                }
            }
        }