示例#1
0
        public void SetUp()
        {
            _mapsApiClient           = new MapsAPIClient(new ConfigurationWrapper().GetEnvironmentVarAsString("GOOGLE_API_SECRET_KEY"));
            _addressGeocodingService = new GoogleMapsAddressGeocodingService(_mapsApiClient);

            _fixture = new GoogleMapsDistanceMatrixAddressProximityService(_mapsApiClient, _addressGeocodingService);
        }
示例#2
0
 private static void NearbySearch(MapsAPIClient client, GeocodeResponse geocode)
 {
     var places = client.Places.NearbySearch(
         geocode.Results[0]
         .Geometry.Location,
         rankBy: PlaceRankByEnum.Distance,
         placeType: PlaceSearchTypeEnum.ElectronicsStore);
 }
示例#3
0
 private static void RadarSearch(MapsAPIClient client, GeocodeResponse geocode)
 {
     var radarPlaces = client.Places.RadarSearch(
         geocode.Results[0]
         .Geometry.Location,
         10,
         placeType: PlaceSearchTypeEnum.ATM);
 }
示例#4
0
 private static void SnapToRoads(MapsAPIClient client)
 {
     var snap = client.Roads.SnapToRoads(new List <IGeoCoordinatesLocation>()
     {
         new GeoCoordinatesLocation(35.27801, 149.12958),
         new GeoCoordinatesLocation(-35.28032, 149.12907)
     });
 }
示例#5
0
 private static void GetDirections(MapsAPIClient client)
 {
     var directions = client.Directions.GetDirections(
         new AddressLocation("Chicago,IL"),
         new AddressLocation("Los Angeles,CA"),
         waypoints: new List <Location>
     {
         new AddressLocation("Joplin,MO"),
         new AddressLocation("Oklahoma City,OK")
     });
 }
示例#6
0
        /// <summary>
        /// Gets the loc.
        /// </summary>
        /// <param name="store">The store.</param>
        /// <returns>StoreEntity.</returns>
        private StoreEntity GetLoc(StoreEntity store)
        {
            var client   = new MapsAPIClient(GOOGLEKEY);
            var addressx = store.Address + ", " + store.City + ", " + store.State;

            var geocodeResult = client.Geocoding.Geocode(addressx);

            store.Lat = geocodeResult.Results[0].Geometry.Location.Latitude;
            store.Lng = geocodeResult.Results[0].Geometry.Location.Longitude;

            return(store);
        }
示例#7
0
 private static void AutoComplete(MapsAPIClient client)
 {
     var autoComplete = client.Places.AutoComplete(
         "Google",
         location: new GeoCoordinatesLocation(-33.86746, 151.207090),
         offset: 3,
         language: "en-AU",
         types: new[] { "geocode" },
         components: new ComponentsFilter {
         ["country"] = "au"
     }
         );
 }
示例#8
0
        public Places GetPlace(string zip)
        {
            Places places = new Places();

            places.Zipcode = zip;
            var client   = new MapsAPIClient(GOOGLEKEY);
            var addressx = zip;

            var geocodeResult = client.Geocoding.Geocode(addressx);

            places.Latitude  = geocodeResult.Results[0].Geometry.Location.Latitude;
            places.Longitude = geocodeResult.Results[0].Geometry.Location.Longitude;
            places.PlaceID   = geocodeResult.Results[0].PlaceId;
            return(places);
        }
示例#9
0
        public void DisCoveryService()
        { // Create the service.
            //to do remove from here
            var client = new MapsAPIClient("AIzaSyC29znWjdwUcxAqvmlBQfa_0fGGwOQKfAo");
            // Geocoding an address
            var geocodeResult = client.Geocoding.Geocode("1600 Amphitheatre Parkway, Mountain View, CA");

            // Look up an address with reverse geocoding
            var reverseGeocodeResult = client.Geocoding.ReverseGeocode(40.714224, -73.961452);

            // Request directions via public transit
            var directionsResult = client.Directions.GetDirections("jerusalem",
                                                                   "tel aviv",
                                                                   mode: TransportationModeEnum.Transit,
                                                                   departureTime: DateTime.Now);
        }
示例#10
0
 private static void GetDistanceMatrix(MapsAPIClient client)
 {
     var matrix = client.DistanceMatrix.GetDistanceMatrix(
         new List <IAddressOrGeoCoordinatesLocation>
     {
         new AddressLocation("Vancouver BC"),
         new AddressLocation("Seattle")
     },
         new List <IAddressOrGeoCoordinatesLocation>
     {
         new AddressLocation("San Francisco"),
         new AddressLocation("Victoria BC")
     },
         TransportationModeEnum.Bicycling,
         language: "fr-FR");
 }
示例#11
0
        public string GetInfo(double lng, double lat)
        {
            var    client = new MapsAPIClient(GOOGLEKEY);
            string zip    = "";
            // Look up an address with reverse geocoding
            var reverseGeocodeResult = client.Geocoding.ReverseGeocode(lat, lng);

            var fadd = reverseGeocodeResult.Results[0].FormattedAddress;
            int len  = fadd.Length;

            if (len > 20)
            {
                zip = fadd.Substring(len - 10, len - 5);
            }



            return(zip);
        }
示例#12
0
 private static void FindPlace(MapsAPIClient client)
 {
     var findPlaceResponse = client.Places.FindPlace(
         "Google",
         FindPlaceInputTypeEnum.TextQuery,
         fields: new []
     {
         FindPlaceFieldsEnum.place_id,
         FindPlaceFieldsEnum.name,
         FindPlaceFieldsEnum.formatted_address,
         FindPlaceFieldsEnum.id,
         FindPlaceFieldsEnum.icon,
         FindPlaceFieldsEnum.geometry,
         FindPlaceFieldsEnum.permanently_closed,
         FindPlaceFieldsEnum.photos,
         FindPlaceFieldsEnum.plus_code,
         //FindPlaceFieldsEnum.scope,
         FindPlaceFieldsEnum.types
     });
 }
示例#13
0
        public async Task <IActionResult> Create([Bind("Id,Name,Surname,BirthDate,PhoneNum,Adress,Passport,Email,Photo")] BrokerCreateEditModel brokerModel)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (brokerModel.Photo != null)
                {
                    string uploadFolder = Path.Combine(hostingEnvironment.WebRootPath, "brokerImages");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + brokerModel.Photo.FileName;
                    string filePath   = Path.Combine(uploadFolder, uniqueFileName);
                    var    fileStream = new FileStream(filePath, FileMode.Create);
                    brokerModel.Photo.CopyTo(fileStream);
                    fileStream.Close();
                }
                if (brokerModel.Adress == null)
                {
                    brokerModel.Adress = "вул. Матеюка 20";
                }
                var client        = new MapsAPIClient("AIzaSyBfckBchOpn-lM4oJ9V9nBDBZmmlousIRQ");
                var geocodeResult = client.Geocoding.Geocode(brokerModel.Adress).Results.FirstOrDefault().Geometry.Location;

                Brokers newBroker = new Brokers
                {
                    Name         = brokerModel.Name,
                    Surname      = brokerModel.Surname,
                    BirthDate    = brokerModel.BirthDate,
                    PhoneNum     = brokerModel.PhoneNum,
                    Adress       = brokerModel.Adress,
                    GeoLatitude  = (Double)geocodeResult.Latitude,
                    GeoLongitude = (Double)geocodeResult.Longitude,
                    Passport     = brokerModel.Passport,
                    Email        = brokerModel.Email,
                    ImagePath    = uniqueFileName
                };
                _context.Add(newBroker);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(brokerModel));
        }
示例#14
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">Arguments</param>
        static void Main(string[] args)
        {
            // Get client
            var client = new MapsAPIClient("---YOUR API KEY---");

            //Find Place
            FindPlace(client);

            // Get directions
            GetDirections(client);

            // Geocode address
            var geocode = Geocode(client);

            // Search places nearby
            NearbySearch(client, geocode);

            // Radar search places
            RadarSearch(client, geocode);

            // Get timezone
            GetTimeZone(client);

            // Snap to roads
            SnapToRoads(client);

            // Get distance matrix
            GetDistanceMatrix(client);

            // Get place photo
            GetPlacePhoto(client);

            // Autocomplete
            AutoComplete(client);

            // Info
            Console.WriteLine();
            Console.WriteLine(@"Press ENTER to exit...");
            Console.ReadLine();
        }
示例#15
0
        public async Task <IActionResult> Edit(int id, [Bind("Name,Surname,BirthDate,PhoneNum,Passport,Adress,Email,Password,Photo, ImagePath")] BrokerCreateEditModel brokerModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var findbroker = await _context.Brokers.FindAsync(id);

                    string uniqueFileName = findbroker.ImagePath;
                    if (brokerModel.Photo != null)
                    {
                        string uploadFolder = Path.Combine(hostingEnvironment.WebRootPath, "brokerImages");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + brokerModel.Photo.FileName;
                        string filePath   = Path.Combine(uploadFolder, uniqueFileName);
                        var    fileStream = new FileStream(filePath, FileMode.Create);
                        brokerModel.Photo.CopyTo(fileStream);
                        fileStream.Close();
                    }

                    findbroker.Name      = brokerModel.Name;
                    findbroker.Surname   = brokerModel.Surname;
                    findbroker.BirthDate = brokerModel.BirthDate;
                    findbroker.PhoneNum  = brokerModel.PhoneNum;
                    findbroker.Adress    = brokerModel.Adress;

                    /* if (brokerModel.Adress == "вул. Матеюка 20")
                     * {
                     *   findbroker.GeoLatitude = brokerModel.GeoLatitude;
                     *   findbroker.GeoLongitude = brokerModel.GeoLongitude;
                     * }
                     * else
                     * {*/
                    var client        = new MapsAPIClient("AIzaSyBfckBchOpn-lM4oJ9V9nBDBZmmlousIRQ");
                    var geocodeResult = client.Geocoding.Geocode(brokerModel.Adress).Results.FirstOrDefault().Geometry.Location;
                    findbroker.GeoLatitude  = (Double)geocodeResult.Latitude;
                    findbroker.GeoLongitude = (Double)geocodeResult.Longitude;
                    //}
                    findbroker.Passport = brokerModel.Passport;
                    findbroker.Email    = brokerModel.Email;

                    if (uniqueFileName != null)
                    {
                        string   FileName = findbroker.ImagePath;
                        string   ImPath   = Path.Combine(hostingEnvironment.WebRootPath, "brokerImages") + "\\" + FileName;
                        FileInfo file     = new FileInfo(ImPath);
                        if (file.Exists)
                        {
                            file.Delete();
                        }
                        findbroker.ImagePath = uniqueFileName;
                    }

                    _context.Update(findbroker);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BrokersExists(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            var broker = _context.Brokers.Find(id);

            return(View(broker));
        }
示例#16
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public RoadsAPI(MapsAPIClient client) : base(client)
 {
 }
示例#17
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public TimeZoneAPI(MapsAPIClient client) : base(client)
 {
 }
示例#18
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public PlacesAPI(MapsAPIClient client) : base(client)
 {
 }
示例#19
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public StreetViewImageAPI(MapsAPIClient client) : base(client)
 {
 }
        public IActionResult ShowRoute(string from, string to)
        {
            var client           = new MapsAPIClient("AIzaSyDfFiQB4uFA8_lS-24Ll1EFUXxfGVGoJWs");
            var directionsResult = client.Directions.GetDirections(from, to, TransportationModeEnum.Walking, null, true, null, "dutch", UnitSystemEnum.Metric, null, DateTime.Now, null, true, null, TransitRoutingPreferenceEnum.LessWalking, TrafficModelEnum.BestGuess);

            List <GetDirectionsRouteResult> routes = directionsResult.Routes;

            //List<Vector> vectors = new List<Vector>();
            //VectorNeighbor neighbor = null;

            foreach (var route in directionsResult.Routes)
            {
                foreach (var leg in route.Legs)
                {
                    foreach (var step in leg.Steps)
                    {
                        Vector     parent      = new Vector(step.StartLocation.Latitude, step.StartLocation.Longitude);
                        Vector     child       = new Vector(step.EndLocation.Latitude, step.EndLocation.Longitude);
                        VectorPath vectorPath1 = new VectorPath(step.Distance.Value)
                        {
                            VectorId1Navigation = parent,
                            VectorId2Navigation = child
                        };
                        VectorPath vectorPath2 = new VectorPath(step.Distance.Value)
                        {
                            VectorId1Navigation = child,
                            VectorId2Navigation = parent
                        };

                        if (!_context.Vectors.Any(x => x.Latitude == step.StartLocation.Latitude && x.Longitude == step.StartLocation.Longitude))
                        {
                            _context.Vectors.Add(parent);
                            _context.VectorPaths.Add(vectorPath1);
                            _context.SaveChanges();
                        }

                        if (!_context.Vectors.Any(x =>
                                                  x.Latitude == step.EndLocation.Latitude && x.Longitude == step.EndLocation.Longitude))
                        {
                            _context.Vectors.Add(child);
                            _context.VectorPaths.Add(vectorPath2);
                            _context.SaveChanges();
                        }

                        parent = _context.Vectors.First(x =>
                                                        x.Latitude == step.StartLocation.Latitude &&
                                                        x.Longitude == step.StartLocation.Longitude);
                        child = _context.Vectors.First(x =>
                                                       x.Latitude == step.EndLocation.Latitude &&
                                                       x.Longitude == step.EndLocation.Longitude);

                        if (!_context.VectorPaths.Any(x => x.VectorId1 == parent.Id && x.VectorId2 == child.Id))
                        {
                            vectorPath1 = new VectorPath(step.Distance.Value)
                            {
                                VectorId1Navigation = parent,
                                VectorId2Navigation = child
                            };
                            _context.VectorPaths.Add(vectorPath1);
                        }
                        if (!_context.VectorPaths.Any(x => x.VectorId1 == child.Id && x.VectorId2 == parent.Id))
                        {
                            vectorPath2 = new VectorPath(step.Distance.Value)
                            {
                                VectorId1Navigation = child,
                                VectorId2Navigation = parent
                            };
                            _context.VectorPaths.Add(vectorPath2);
                        }
                    }
                }
            }
            _context.SaveChanges();

            return(View(directionsResult));
        }
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public DistanceMatrixAPI(MapsAPIClient client) : base(client)
 {
 }
示例#22
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 protected MapsAPI(MapsAPIClient client)
 {
     Client = client;
 }
示例#23
0
        private static GeocodeResponse Geocode(MapsAPIClient client)
        {
            var geocode = client.Geocoding.Geocode("203-1200 Saint-Jean-Baptiste, Quebec");

            return(geocode);
        }
示例#24
0
 private static void GetPlacePhoto(MapsAPIClient client)
 {
     var resultPhoto = client.Places.GetPlacePhoto(
         "CnRtAAAATLZNl354RwP_9UKbQ_5Psy40texXePv4oAlgP4qNEkdIrkyse7rPXYGd9D_Uj1rVsQdWT4oRz4QrYAJNpFX7rzqqMlZw2h2E2y5IKMUZ7ouD_SlcHxYq1yL4KbKUv3qtWgTK0A6QbGh87GB3sscrHRIQiG2RrmU_jF4tENr9wGS_YxoUSSDrYjWmrNfeEHSGSc3FyhNLlBU",
         maxWidth: 400);
 }
示例#25
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public GeometryAPI(MapsAPIClient client) : base(client)
 {
 }
示例#26
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">Arguments</param>
        static void Main(string[] args)
        {
            // Get client
            var client = new MapsAPIClient("---YOUR API KEY---");

            // Get directions
            var directions = client.Directions.GetDirections(
                new AddressLocation("Chicago,IL"),
                new AddressLocation("Los Angeles,CA"),
                waypoints: new List <Location>
            {
                new AddressLocation("Joplin,MO"),
                new AddressLocation("Oklahoma City,OK")
            });

            // Geocode address
            var geocode = client.Geocoding.Geocode("203-1200 Saint-Jean-Baptiste, Quebec");

            // Search places nearby
            var places = client.Places.NearbySearch(
                geocode.Results[0].Geometry.Location,
                rankBy: PlaceRankByEnum.Distance,
                placeType: PlaceSearchTypeEnum.ElectronicsStore);

            // Radar search places
            var radarPlaces = client.Places.RadarSearch(
                geocode.Results[0].Geometry.Location,
                10,
                placeType: PlaceSearchTypeEnum.ATM);

            // Get timezone
            var timezone = client.TimeZone.GetTimeZone(35.27801, 149.12958, DateTime.Now);

            // Snap to roads
            var snap = client.Roads.SnapToRoads(new List <IGeoCoordinatesLocation>()
            {
                new GeoCoordinatesLocation(35.27801, 149.12958),
                new GeoCoordinatesLocation(-35.28032, 149.12907)
            });

            // Get distance matrix
            var matrix = client.DistanceMatrix.GetDistanceMatrix(
                new List <IAddressOrGeoCoordinatesLocation>
            {
                new AddressLocation("Vancouver BC"),
                new AddressLocation("Seattle")
            },
                new List <IAddressOrGeoCoordinatesLocation>
            {
                new AddressLocation("San Francisco"),
                new AddressLocation("Victoria BC")
            },
                TransportationModeEnum.Bicycling,
                language: "fr-FR");

            // Get place photo
            var resultPhoto = client.Places.GetPlacePhoto(
                "CnRtAAAATLZNl354RwP_9UKbQ_5Psy40texXePv4oAlgP4qNEkdIrkyse7rPXYGd9D_Uj1rVsQdWT4oRz4QrYAJNpFX7rzqqMlZw2h2E2y5IKMUZ7ouD_SlcHxYq1yL4KbKUv3qtWgTK0A6QbGh87GB3sscrHRIQiG2RrmU_jF4tENr9wGS_YxoUSSDrYjWmrNfeEHSGSc3FyhNLlBU",
                maxWidth: 400);

            // Autocomplete
            var autoComplete = client.Places.AutoComplete(
                "Google",
                location: new GeoCoordinatesLocation(-33.86746, 151.207090),
                offset: 3,
                language: "en-AU",
                types: new[] { "geocode" },
                components: new ComponentsFilter {
                ["country"] = "au"
            }
                );

            // Info
            Console.WriteLine();
            Console.WriteLine(@"Press ENTER to exit...");
            Console.ReadLine();
        }
示例#27
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public ElevationAPI(MapsAPIClient client) : base(client)
 {
 }
示例#28
0
 private static void GetTimeZone(MapsAPIClient client)
 {
     var timezone = client.TimeZone.GetTimeZone(35.27801, 149.12958, DateTime.Now);
 }
示例#29
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public GeocodingAPI(MapsAPIClient client) : base(client)
 {
 }
示例#30
0
 /// <summary>
 /// Create a new instance
 /// </summary>
 /// <param name="client">API client</param>
 public DirectionsAPI(MapsAPIClient client) : base(client)
 {
 }