Beispiel #1
0
        //Takes and address and gives back lat,lng as result
        //lat = result.Item1, lng = result.Item2
        public async Task <Tuple <double, double> > geoCode(string address)
        {
            GoogleGeocodingAPI.GoogleAPIKey = " AIzaSyBHnO1TC2wWkYXssMdJhwdJt3jUia9bpyY ";
            Tuple <double, double> result = await GoogleGeocodingAPI.GetCoordinatesFromAddressAsync(address);

            return(result);
        }
        private async Task <MapPoint> AddLongLatAsync(string apartmentAddress)
        {
            MapPoint point;

            // Getting the location of the address
            try
            {
                GoogleGeocodingAPI.GoogleAPIKey = "AIzaSyDKp42W_7Sc_kcVimZm-pPKG2TCXeFdzto";
                var result = await GoogleGeocodingAPI.GetCoordinatesFromAddressAsync(apartmentAddress);

                point = new MapPoint
                {
                    Latitude  = result.Item1,
                    Longitude = result.Item2
                };
            }
            catch (Exception ex)
            {
                point = new MapPoint
                {
                    Latitude  = 32.1637206,
                    Longitude = 34.8647352
                };
            }

            return(point);
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Press anything to start calling API");
            var ok = Console.ReadKey();

            GoogleGeocodingAPI.GoogleAPIKey = GooglePlacesAPI.GoogleAPIKey = TesterRes.GoogleAPIKey; // create your own TesterRes resource and put your google api there


            //GEOCODING

            var result1   = Task.Run(async() => await GoogleGeocodingAPI.SearchAddressAsync("100 Market St, Southbank")).Result;
            var location1 = result1.Results.FirstOrDefault().Geometry.Location;


            var location2 = Task.Run(async() => await GoogleGeocodingAPI.GetCoordinatesFromAddressAsync("322 Kings Way, South Melbourne VIC 3205")).Result;
            var result2   = Task.Run(async() => await GoogleGeocodingAPI.GetAddressFromCoordinatesAsync(location2.Item1, location2.Item2)).Result;

            var distanceBetweenThem = Helper.GetDistance(location1.Lat, location2.Item1, location1.Lng, location2.Item2);
            var midlePoint          = Helper.GetMiddleCoordinates(location1.Lat, location2.Item1, location1.Lng, location2.Item2);
            var midlePointLocation  = Task.Run(async() => await GoogleGeocodingAPI.GetAddressFromCoordinatesAsync(midlePoint.Item1, midlePoint.Item2)).Result;


            //PLACES

            var result4 = Task.Run(async() => await GooglePlacesAPI.SearchPlaceNearBy(lat: midlePoint.Item1, lng: midlePoint.Item2, radiusInMeters: distanceBetweenThem * 1000, type: GuigleAPI.Model.PlaceType.liquor_store)).Result;

            var result5 = Task.Run(async() => await GooglePlacesAPI.SearchPlaceNearBy(query: "100 Market St, Southbank")).Result;
        }
        public async Task <IActionResult> Index(SearchViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            GoogleGeocodingAPI.GoogleAPIKey = "AIzaSyCGsNbs9jtuhItVf8d26SejNlAgfpRF-Oo";
            var result = await GoogleGeocodingAPI.GetCoordinatesFromAddressAsync(model.Location);

            var latitude  = result.Item1;
            var longitude = result.Item2;

            return(RedirectToAction("Index", "Home", new { latitude, longitude }));
        }
Beispiel #5
0
        //add location
        public async Task <JsonResult> FillCoordinates()
        {
            var inst = InstRep.FindBy(i => i.lat == null && i.street != null && i.building != null);

            GoogleGeocodingAPI.GoogleAPIKey = "AIzaSyDYOPXa0ERMkgOab3zsIUKvlUB2xywD6a4";
            int k             = inst.Count();
            int CountRequests = 0;

            foreach (var item in inst.ToList())
            {
                CountRequests++;
                if (item.lat == null)
                {
                    string addr = item.City.Region.name + " область, " + item.City.name + ", " +
                                  item.street + ", " + item.building;
                    var result = await GoogleGeocodingAPI.GetCoordinatesFromAddressAsync(addr);

                    Thread.Sleep(2000);
                    if (result != null)
                    {
                        item.lat = result.Item1;
                        item.lng = result.Item2;
                        InstRep.AddOrUpdate(item);
                    }
                    else
                    {
                        item.lat = 1;
                        item.lng = 1;
                        InstRep.AddOrUpdate(item);
                    }
                }
                if (CountRequests > 2200)
                {
                    break;
                }
            }
            return(Json(null, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public async Task <ActionResult> MainPage(EmployeeListViewModel obj, int?UserId, DateTime?date_)
        {
            if (User.IsInRole("admin") || User.IsInRole("DD") || User.Identity.Name.Equals("aleshina"))
            {
                return(Redirect("/Report/MonitoringPanel"));
            }
            else
            {
                var model = new EmployeeListViewModel(5);
                model.month_           = DateTime.Now.Month;
                model.year_            = DateTime.Now.Year.ToString();
                ViewBag.DetalizationId = new SelectList(ActDetalizationRep.GetAll(), "id", "name");
                model.UserId           = MyId;
                model.CurrentPage      = obj.CurrentPage;
                ViewBag.CurrentPage    = model.CurrentPage;
                if (date_ != null)
                {
                    model.date_ = (DateTime)date_;
                }

                //for map - receive home coordinates
                var user = CUserRep.FindBy(i => i.id == MyId).First();
                //var user = users.Where(i => i.Id == model.UserId).First();
                model.UserHomeAddress = user.home_address;
                if (user.lat != null)
                {
                    model.UserHomeAddressLat = user.lat.ToString().Replace(',', '.');
                    model.UserHomeAddressLon = user.lng.ToString().Replace(',', '.');
                }
                else
                {
                    GoogleGeocodingAPI.GoogleAPIKey = "AIzaSyAHhYTOKh9Am1DUh44uTLTdTnA7IYjUi7Y";
                    //AIzaSyAHhYTOKh9Am1DUh44uTLTdTnA7IYjUi7Y
                    //AIzaSyDYOPXa0ERMkgOab3zsIUKvlUB2xywD6a4
                    var result = await GoogleGeocodingAPI.GetCoordinatesFromAddressAsync(model.UserHomeAddress);

                    if (result != null)
                    {
                        user.lat = result.Item1;
                        user.lng = result.Item2;
                        model.UserHomeAddressLat = user.lat.ToString().Replace(',', '.');
                        model.UserHomeAddressLon = user.lng.ToString().Replace(',', '.');
                        var viewUs = CUserRep.FindBy(i => i.id == user.id).First();
                        viewUs.lat = user.lat;
                        viewUs.lng = user.lng;
                        CUserRep.AddOrUpdate(viewUs);
                    }
                }

                var DependentUsers = CUserRep.FindBy(i => (i.boss_id == MyId || i.top_boss_id == MyId) && i.user_state_id != 3).Distinct()
                                     .Select(i => new Report_ {
                    id = i.id, name = i.LastName + " " + i.FirstName
                }).ToList();
                if (User.IsInRole("RM"))
                {
                    ViewBag.DependentUsers = new SelectList(DependentUsers, "id", "name");
                }
                else if (User.IsInRole("admin"))
                {
                    ViewBag.DependentUsers = new SelectList(CUserRep.FindBy(i => (i.user_position_id == 9 || i.user_position_id == 18) && i.user_state_id != 3)
                                                            .Select(i => new Report_ {
                        id = i.id, name = i.LastName + " " + i.FirstName
                    }).ToList(), "id", "name");
                }

                // auto filling homeaddress of cusers
                //    foreach (var item in users)
                //    {
                //        if (item.lat != null)
                //        {
                //            model.UserHomeAddressLat = item.lat.ToString();
                //            model.UserHomeAddressLon = item.lng.ToString();
                //        }
                //        else
                //        {
                //            model.UserHomeAddress = item.home_address;
                //            GoogleGeocodingAPI.GoogleAPIKey = "AIzaSyAHhYTOKh9Am1DUh44uTLTdTnA7IYjUi7Y";
                //            //AIzaSyAHhYTOKh9Am1DUh44uTLTdTnA7IYjUi7Y
                //            //AIzaSyDYOPXa0ERMkgOab3zsIUKvlUB2xywD6a4
                //            var result = await GoogleGeocodingAPI.GetCoordinatesFromAddressAsync(model.UserHomeAddress);
                //            if (result != null)
                //            {
                //                item.lat = result.Item1;
                //                item.lng = result.Item2;
                //                model.UserHomeAddressLat = item.lat.ToString().Replace(',', '.');
                //                model.UserHomeAddressLon = item.lng.ToString().Replace(',', '.');
                //                var viewUs = CUserRep.FindBy(i => i.id == item.Id).FirstOrDefault();
                //                if (viewUs!=null)
                //                {
                //                    viewUs.lat = item.lat;
                //                    viewUs.lng = item.lng;
                //                    CUserRep.AddOrUpdate(viewUs);
                //                }
                //            }
                //            Thread.Sleep(1000);
                //        }
                //}

                return(View(model));
            }
        }