Example #1
0
        private static List <Place> GetListOfPlaces(string apiKey, PlaceJson response, Location location, List <Place> setOfNearbyPlaces)
        {
            List <Place> places = new List <Place>();

            foreach (var item in response.results)
            {
                if (setOfNearbyPlaces.FirstOrDefault(p => p.Location.Equals(item.geometry.location)) == null)
                {
                    Place tmp = new Place()
                    {
                        PlaceId    = item.place_id,
                        PriceLevel = item.price_level,
                        Name       = item.name,
                        Location   = item.geometry.location,
                        IconUrl    = item.icon,
                        Address    = item.vicinity
                    };

                    try
                    {
                        tmp.Popularity = HandlePlaceDetails.GetPopularity(apiKey, tmp.PlaceId);
                    }
                    catch { }

                    var userCoordinate  = new GeoCoordinate(location.lat, location.lng);
                    var placeCoordinate = new GeoCoordinate(tmp.Location.lat, tmp.Location.lng);

                    tmp.Distance = Math.Round(userCoordinate.GetDistanceTo(placeCoordinate), 2);

                    places.Add(tmp);
                }
            }

            return(places);
        }
Example #2
0
        public static List <Place> UpdateNearbyPlaces(string apiKey, Location location, int radius, PlaceType type, List <Place> setOfNearbyPlaces)
        {
            try
            {
                string constructedUrl = GOOGLE_BASE_URL + string.Format(PLACE_SEARCH, location.lat.ToString().Replace(",", "."), location.lng.ToString().Replace(",", "."), radius, type.ToString(), apiKey);

                PlaceJson placesJson = HttpRequest.GetNearbyPlaceResponse(constructedUrl);
                return(GetListOfPlaces(apiKey, placesJson, location, setOfNearbyPlaces));
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Example #3
0
        public ActionResult AllLegacyReport()
        {
            var all    = new List <PlaceJson>();
            var places = ServiceConfig.CartoPlaceService.ListPlaces();

            //foreach(var place in places.OrderBy(x => x.Country.CountryID).ThenBy(x => x.PlaceType).ThenBy(x => x.Name))
            //foreach (var place in places.OrderBy(x => x.Country.CountryID).ThenByDescending(x => x.Bounds.Area).ThenByDescending(x => (-x.Center.Longitude + x.Center.Latitude)))
            foreach (var place in places.OrderBy(x => x.Country.CountryID).ThenByDescending(x => x.Center.Latitude).ThenBy(x => x.Center.Longitude))
            {
                var one = new PlaceJson();
                one.key     = place.Key;
                one.type    = place.PlaceType.ToString();
                one.country = place.Country.CountryID;
                one.name    = place.Name;
                one.lat     = place.Center.Latitude;
                one.lng     = place.Center.Longitude;
                all.Add(one);
            }

            return(Json(all, JsonRequestBehavior.AllowGet));
        }