Ejemplo n.º 1
0
        /// <summary>
        /// Gets the retailer map page for a particular zip and mile range
        /// </summary>
        /// <param name="zip">The zip of the user, on which to center the map</param>
        /// <param name="range">The range in miles to find retailers within</param>
        /// <returns>The retailer map view</returns>
        // GET: RetailerMap
        public async Task <ActionResult> Index(string zip = "", int range = 50)
        {
            // If zip is passed, get coords for zip
            if (zip != "")
            {
                try
                {
                    var googleMapsClient = new GoogleMapsClient();
                    userLocation = await googleMapsClient.GeocodeAddress(zip);
                }
                catch
                {
                    userLocation = new LatLng(43, -86);
                }
            }

            ViewBag.Location = userLocation;

            // Pass filter terms back to view
            ViewBag.Zip   = zip;
            ViewBag.Range = range;

            // Zoom is based on search range
            ViewBag.Zoom          = GoogleMapsClient.RadiusToZoom(range);
            ViewBag.GoogleMapsUrl = GoogleMapsClient.baseUrl + "js?key=" + GoogleMapsClient.apiKey + "&callback=initialMap";
            return(View());
        }
        public async Task GetDistance_ValidInput_PositiveDuration()
        {
            var target   = new GoogleMapsClient(Settings.GoogleMapsKey);
            var duration = await target.GetDistnace(Settings.DirectionOrigin, Settings.DirectionDestination);

            Assert.True(duration > 0);
        }
Ejemplo n.º 3
0
        /*
         * Pobiera jako parametr wspolrzedne urzytkownika korzystajacego z aplikacji oraz klucz API
         * ustawia obecna droge liczona w czasie oraz dystancie od wybranego parkingu "this", zwraca obiekt z API Google
         *
         * */
        public DistanceMatrixObject distanceFromUserLocation(Location location, string path)
        {
            string origin               = RequestFormatter.geometryLocationFormatter(location.lat, location.lng);
            string destination          = RequestFormatter.geometryLocationFormatter(this.GpsLat, this.GpsLng);
            DistanceMatrixObject result = GoogleMapsClient.GetDistanceMatrixAsync(origin, destination, path).Result;

            this.DurationToUserPlace = result.Rows[0].Elements[0].Duration.Value;
            this.DistanceToUserPlace = result.Rows[0].Elements[0].Distance.Value;
            return(result);
        }
Ejemplo n.º 4
0
        public static async Task <int> GetCommuteTime([ActivityTrigger] object input)
        {
            var key         = Settings.GoogleMapsKey;
            var origin      = Settings.DirectionOrigin;
            var destination = Settings.DirectionDestination;

            var client = new GoogleMapsClient(key);

            return(await client.GetDistnace(origin, destination));
        }
Ejemplo n.º 5
0
        public void GetAllMetadata()
        {
            var cache = new CachingStrategy
            {
                new FileCacheLayer(GmapsStreamingAssetsDir)
            };

            var gmaps = new GoogleMapsClient(apiKey, signingKey, metadataDecoder, geocodingDecoder, cache);
            var files = gmaps.CachedMetadata.ToArray();

            Assert.AreNotEqual(0, files.Length);
        }
Ejemplo n.º 6
0
    public IActionResult List()
    {
        var parkings = (from e in db.Parking select e).ToList();

        List <ParkingExtensions> exParkings = ParkingExtensions.takeParkingExtensionsWithNumberPlaces(parkings);

        string origin      = String.Format("{0},{1}", parkings[0].GpsLat, parkings[0].GpsLng);
        string destination = String.Format("{0},{1}", parkings[1].GpsLat, parkings[1].GpsLng);

        var temp = GoogleMapsClient.GetDistanceMatrixAsync(origin, destination, config.Value.GoogleApiKey).Result;

        return(View(exParkings));
    }
Ejemplo n.º 7
0
        public async Task GetMetadataByFileRefAsync()
        {
            var cache = new CachingStrategy
            {
                new FileCacheLayer(GmapsStreamingAssetsDir)
            };

            var gmaps     = new GoogleMapsClient(apiKey, signingKey, metadataDecoder, geocodingDecoder, cache);
            var metadata  = gmaps.CachedMetadata.FirstOrDefault();
            var pano      = metadata.Pano_id;
            var fileRef   = new ContentReference(pano, MediaType.Application_Json);
            var metadata2 = await cache.LoadAsync(metadataDecoder, fileRef)
                            .ConfigureAwait(false);

            Assert.AreEqual(metadata.Pano_id, metadata2.Pano_id);
        }
        public AddressDialog(string questionText,
                             string deliveryPersonNameText      = "Zadejte prosím celé jméno nového příjemce.",
                             string confirmText                 = "Je tato adresa správně?",
                             string addressNotFoundText         = "Bohužel jsem tuto adresu nenašel. Je opravdu správně?",
                             string questionAgainText           = "Tak nám prosím napište správnou adresu. Nebo ji zkuste napsat podrobněji.",
                             string dontUnderstoodText          = "Tak tomu nerozumím. Ano nebo ne? 😦",
                             string addressNotFoundByGoogleText = "S touto adresou si bohužel nevím rady. Pojďmě si ji projít postupně."
                             )
        {
            _mapApiClient      = new GoogleMapsClient();
            _recognizedAddress = new AddressDM();

            _questionText                = questionText;
            _deliveryPersonNameText      = deliveryPersonNameText;
            _confirmText                 = confirmText;
            _addressNotFound             = addressNotFoundText;
            _dontUnderstoodText          = dontUnderstoodText;
            _questionAgainText           = questionAgainText;
            _addressNotFoundByGoogleText = addressNotFoundByGoogleText;
        }
        public async void ObterCoordenadasGoogleMapsAPI()
        {
            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json")
                         .Build();
            //Arrange
            var endereco = new Endereco
            {
                Rua    = "Rua Vergueiro",
                Numero = 88,
                Cidade = "São Paulo",
                UF     = "SP"
            };
            var googleMapsClient = new GoogleMapsClient(config);

            //Act
            var result = await googleMapsClient.ObterCoordenadas(endereco);

            //Assert
            result.Should().NotBeNull("Resultado incorreto ao buscar coordenadas no API do google maps");
        }
Ejemplo n.º 10
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.ThreadException += Application_ThreadException;

            var metadataDecoder   = new JsonFactory <MetadataResponse>();
            var geocodingDecoder  = new JsonFactory <GeocodingResponse>();
            var userProfile       = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            var assetsRoot        = Path.Combine(userProfile, "Box", "VR Initiatives", "Engineering", "Assets");
            var keyFileName       = Path.Combine(assetsRoot, "DevKeys", "google-streetview.txt");
            var gmapsCacheDirName = Path.Combine(assetsRoot, "GoogleMaps");
            var gmapsCacheDir     = new DirectoryInfo(gmapsCacheDirName);
            var cache             = new CachingStrategy
            {
                new FileCacheLayer(gmapsCacheDir)
            };

            var lines      = File.ReadAllLines(keyFileName);
            var apiKey     = lines[0];
            var signingKey = lines[1];

            gmaps = new GoogleMapsClient(
                apiKey, signingKey,
                metadataDecoder, geocodingDecoder,
                cache);

            imageDecoder = new GDICodec(MediaType.Image_Jpeg);

            form = new ImageViewer();
            form.LocationSubmitted += Form_LocationSubmitted;
            form.LatLngSubmitted   += Form_LatLngSubmitted;
            form.PanoSubmitted     += Form_PanoSubmitted;
            using (form)
            {
                Application.Run(form);
            }
        }
 public async Task GetDistance_InvalidKey_Exception()
 {
     var target = new GoogleMapsClient("12345");
     await Assert.ThrowsAsync <GoogleApiException>(() => target.GetDistnace(Settings.DirectionOrigin, Settings.DirectionDestination));
 }
        public async Task <GeocodingResult> GetGeolocationFromAddress(string address)
        {
            var request = new RestRequest
            {
                Method   = Method.GET,
                Resource = $"maps/api/geocode/json"
            };

            request.AddQueryParameter("address", address);

            var response = await GoogleMapsClient.ExecuteAsync(request);

            //see here for response formatting: https://developers.google.com/maps/documentation/geocoding/intro
            //{
            //    "results" : [
            //       {
            //        ...
            //          "address_components" : [
            //        ...
            //          {
            //              "long_name" : "Mountain View",
            //              "short_name" : "Mountain View",
            //              "types" : [ "locality", "political" ]
            //          },
            //          {
            //              "long_name" : "California",
            //              "short_name" : "CA",
            //              "types" : [ "administrative_area_level_1", "political" ]
            //          }
            //      ],
            //        ...
            //        "geometry" : {
            //            "location" : {
            //                "lat" : 37.4224764,
            //                "lng" : -122.0842499
            //              }
            //        }
            //    ]
            //}
            try
            {
                dynamic parsedResult = JsonConvert.DeserializeObject(response.Content);
                dynamic firstResult = parsedResult.results[0];
                dynamic addressComponents = firstResult.address_components;
                string  city = null, state = null;
                foreach (var addressComponent in addressComponents)
                {
                    var types = addressComponent.types as JArray;

                    if (ContainsValue(types, "administrative_area_level_1"))
                    {
                        state = addressComponent.long_name;
                    }
                    if (ContainsValue(types, "locality"))
                    {
                        city = addressComponent.long_name;
                    }
                }
                dynamic location = firstResult.geometry.location;
                return(new GeocodingResult
                {
                    City = city,
                    State = state,
                    Coordinate = new Coordinate
                    {
                        Latitude = location.lat,
                        Longitude = location.lng
                    }
                });
            }
            catch (Exception ex)
            {
                throw new Exception("Invalid Address", ex);
            }
        }