示例#1
0
        public void SavePlace(GooglePlaceResponse placeResponse)
        {
            foreach (var result in placeResponse.Results)
            {
                if (_context.Places.All(u => u.GoogleId != result.Id) &&
                    result?.OpeningHours != null && result?.Geometry?.Location != null)
                {
                    var TypeId = _context.PlaceTypes
                                 .Where(t => t.Name == "Bar")
                                 .FirstOrDefault().Id;

                    Place place = new Place();

                    place.Id        = Guid.NewGuid();
                    place.GoogleId  = result.Id;
                    place.PlaceId   = result.PlaceId;
                    place.PlaceType = TypeId;
                    place.Name      = result.Name;
                    place.Rating    = result.Rating;
                    place.Adress    = result.Vicinity;
                    place.Location  = new string($"{result.Geometry.Location.Latitude},{result.Geometry.Location.Longitude}");

                    _context.Places.Add(place);
                }
            }
        }
示例#2
0
        void GoogleRequest(string locationString)
        {
            string url = @"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + locationString + "&radius=500&type=bar&key=AIzaSyDNRQleDItpHaASUNyg4nsgGMqtwt8IOLU";

            var result = new WebClient().DownloadString(url);
            GooglePlaceResponse placeResponse = JsonConvert.DeserializeObject <GooglePlaceResponse>(result);

            if (placeResponse.Status == "OK")
            {
                _dataBase.SavePlace(placeResponse);
            }
        }