Пример #1
2
        /// <summary>
        /// Perform a geocode lookup of an address
        /// </summary>
        /// <param name="addr">The address in CSV form line1, line2, postcode</param>
        /// <param name="output">CSV or XML</param>
        /// <returns>LatLng object</returns>
        /// 
        public LatLng GetLatLng(string address)
        {
            var locationService = new GoogleLocationService();
            var point = locationService.GetLatLongFromAddress(address);

            var latitude = point.Latitude;
            var longitude = point.Longitude;

            var latLng = new LatLng()
            {
                Latitude = latitude,
                Longitude = longitude
            };

            return latLng;
        }
    public static void markers_address(object[] lat_long)
    {
        Dictionary<int, Dictionary<string, object>> struc = new Dictionary<int, Dictionary<string, object>>();
        Dictionary<string, object> inner = new Dictionary<string, object>();
        List<string> lat_long_pair = new List<string>();
        for (int i = 0; i < lat_long.Length; i++)
        {
            inner = (Dictionary<string, object>)lat_long.GetValue(i);
            foreach (var pair in inner)
            {
                string a = pair.Key;
                object b = pair.Value;
                string lat_lng_str = (string)Convert.ChangeType(b, typeof(string));
                lat_long_pair.Add(lat_lng_str);
            }
        }

        // convert lat-long to place
        var locationService = new GoogleLocationService();
        // List<string> marker_place = new List<string>();
        var count = 0;
        marker_place.Clear();
        for (int i = 0; i < lat_long_pair.Count; i = i + 2)
        {
            IGeocoder geocoder = new GoogleGeocoder() { };
            try
            {
                IEnumerable<Address> addresses = geocoder.ReverseGeocode(Convert.ToDouble(lat_long_pair[i]), Convert.ToDouble(lat_long_pair[i + 1]));

                foreach (Address adr in addresses)
                {
                    if (count == 0)
                    {
                        string address = adr.FormattedAddress;
                        marker_place.Add(address);
                    }
                    break;
                }
                count = 0;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
    }
Пример #3
0
        public ActionResult Create([Bind(Include = "AdresID,KodPocztowy,Kraj,Miasto,Ulica,NrBudynku,NrLokalu")] Adres adres, long? id, KomuAdres komu)
        {
            if (Session["Auth"] != null)
            {
                if (Session["Auth"].ToString() == "Recepcjonista" || Session["Auth"].ToString() == "Administrator")
                {
                    object redirectTo = null;
                    if (ModelState.IsValid)
                    {
                        switch (komu)
                        {
                            case KomuAdres.Osoba:
                                Osoba osoba = db.Osoby.Find(id);
                                redirectTo = osoba.GetType().BaseType.Name;
                                osoba.Adres = adres;
                                //Google Maps
                                var locationServiceO = new GoogleLocationService();
                                AddressData adrO = new AddressData();
                                adrO.Country = adres.Kraj;
                                adrO.City = adres.Miasto;
                                adrO.Zip = adres.KodPocztowy;
                                adrO.Address = adres.Ulica + " " + adres.NrBudynku + " " + adres.NrLokalu;
                                var pointO = locationServiceO.GetLatLongFromAddress(adrO);
                                osoba.Szerokosc = pointO.Longitude;
                                osoba.Dlugosc = pointO.Latitude;
                                redirectTo = osoba.GetType().BaseType.Name;

                                //adres.Osoba = osoba;
                                break;
                            case KomuAdres.Silownia:
                                Silownia.Models.Silownia silownia = db.Silownie.Find(id);
                                silownia.Adres = adres;
                                var locationServiceS = new GoogleLocationService();
                                AddressData adrS = new AddressData();
                                adrS.Country = adres.Kraj;
                                adrS.City = adres.Miasto;
                                adrS.Zip = adres.KodPocztowy;
                                adrS.Address = adres.Ulica + " " + adres.NrBudynku + " " + adres.NrLokalu;
                                var pointS = locationServiceS.GetLatLongFromAddress(adrS);
                                silownia.Szerokosc = pointS.Longitude;
                                silownia.Dlugosc = pointS.Latitude;
                                redirectTo = silownia.GetType().BaseType.Name;
                                break;
                        }
                        db.Adresy.Add(adres);
                        db.SaveChanges();
                        return RedirectToAction("Index", redirectTo.ToString());
                    }

                    return View(adres);
                }
            }
               return HttpNotFound();
        }
 public ActionResult Details(int? id)
 {
     Cinema model = cinemaGateway.SelectById(id);
     var address = model.CinemaAddress;
     int indexOfHyphen = address.IndexOf('-');
     String addressWithoutPhone = address.Substring(0, indexOfHyphen - 1);
     var locationService = new GoogleLocationService();
     var point = locationService.GetLatLongFromAddress(addressWithoutPhone);
     ViewBag.latCinema = point.Latitude;
     ViewBag.longCinema = point.Longitude;
     return View(model);
 }
Пример #5
0
 private void Maps_Shown(object sender, EventArgs e)
 {
     MapPoint point;
     latlong = "";
     if (this.bEsDireccion)
     {
         var locationservice = new GoogleLocationService();
         point = locationservice.GetLatLongFromAddress(this.sDireccion);
         if (point == null)
             point = locationservice.GetLatLongFromAddress("Ciudad Guzman");
         latlong = point.Latitude + "," + point.Longitude;
     }
     else
     {
         latlong = this.sDireccion;
     }
     string uri = (@"file:///" + UtilLocal.RutaRecursos("maps.html").Replace("\\", "/"));
     wkbMapa.Navigate(uri);
     this.Cargando(true);
 }
Пример #6
0
 // Gets latitude and longitude for a given address using Google's Location Services API
 public void GetGeocode(string address, out double lat, out double lon)
 {
     var googleLocation = new GoogleLocationService();
     var latlon = googleLocation.GetLatLongFromAddress(address);
     lat = latlon.Latitude;
     lon = latlon.Longitude;
 }
Пример #7
0
 public static void ClassInitialize()
 {
     _locationSvc = new GoogleLocationService();
     _coordZapopan = _locationSvc.GetLatLongFromAddress("Zapopan").ToGeoCoord();
     _coordLondon = _locationSvc.GetLatLongFromAddress("London").ToGeoCoord();
 }
 public void DrawScenicDirection()
 {
     var locationService = new GoogleLocationService();
     var start = locationService.GetLatLongFromAddress("The University of Akron,OHIO");
 }
Пример #9
0
        protected async void Button1_Click(object sender, EventArgs e)
        {
            ParseObject job = new ParseObject(typeof(Job).Name);
            ParseObject empjob = new ParseObject(typeof(EmpJobRelation).Name);
            var locationService = new GoogleLocationService();
            var point = locationService.GetLatLongFromAddress(txtlocation.Text);
            DateTime selected=Calendar1.SelectedDate;

            DateTime dt = new DateTime(selected.Year, selected.Month, selected.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            //var latitude = point.Latitude;
            //var longitude = point.Longitude;
            //Response.Write(latitude + "" + longitude);
            var addpoint = new ParseGeoPoint(point.Latitude, point.Longitude);
            try
            {
                var selectedValue = LiEmployee.SelectedItem;
                //User userObject = items[selectedValue];
                //Response.Write((selectedValue.Value));


                job[MemberInfoGetting.GetMemberName(() => new Job().name)] = JobTitle.Text;
                job[MemberInfoGetting.GetMemberName(() => new Job().description)] = JobDescription.Text;
                //job[MemberInfoGetting.GetMemberName(() => new Job().EmployeeId)] = selectedValue.Value;
                job[MemberInfoGetting.GetMemberName(() => new Job().content)] = JsonConvert.SerializeObject(allcontent);
                job[MemberInfoGetting.GetMemberName(() => new Job().Status)] = JobControlls.JobStatusCode[8];
                job[MemberInfoGetting.GetMemberName(() => new Job().jobDate)] = dt;
                job[MemberInfoGetting.GetMemberName(() => new Job().location)]=txtlocation.Text;
                job[MemberInfoGetting.GetMemberName(() => new Job().locCoordinate)]=addpoint;
                empjob[MemberInfoGetting.GetMemberName(() => new Job().EmployeeId)]=selectedValue.Value;
                
                await job.SaveAsync();
                await empjob.SaveAsync();
                IEnumerable<ParseObject> query  =await ParseObject.GetQuery(typeof(EmpJobRelation).Name)
                    .WhereEqualTo(MemberInfoGetting.GetMemberName(() => new Job().EmployeeId), selectedValue.Value).FindAsync();
                foreach (ParseObject obj in query)
                {
                    empjobrel.Add(new EmpJobRelation()
                    {
                        Id=obj.ObjectId
                    }
                        );
 
                }
                //ParseObject p;
                //var relaiton = p.GetRelation<ParseObject>("UserRelation");
                foreach(var a in empjobrel)
                {

                    job[MemberInfoGetting.GetMemberName(() => new Job().UserRelation)] = a.Id;
                }
                
                await job.SaveAsync();
                Lblerror.Text = "Saved Successfully";
                

            }
            catch(Exception en)
            {
                Lblerror.Text = en.Message;
            }
            //var newJob = new Job { JobName = JobTitle.Text, JobDesc = JobDescription.Text, AssignedUser = selectedValue.Value };
            ////Debug.WriteLine("" + selectedValue.Id);
            // await InsertnewJob(newJob);
        }
Пример #10
0
        //get the geocoordinates of an area based on a location in the tweet body.
        public static GeoCoordinate getCoordByStreet(string address)
        {
            var gls = new GoogleLocationService();
            GeoCoordinate coordFromStreet = new GeoCoordinate();
            try
            {
                var latlong = gls.GetLatLongFromAddress(address);
                coordFromStreet.Latitude = latlong.Latitude;
                coordFromStreet.Longitude = latlong.Longitude;
                return coordFromStreet;
            }

            catch
            {
                System.Console.WriteLine("Google maps error.");
                return null;
            }
        }
Пример #11
-1
 public MapPoint GetLatLong(string address, string suburb, string city, string country, string postcode)
 {
     var locationString = LocationToString(address, suburb, city, country, postcode);
     var locationService = new GoogleLocationService();
     var point = locationService.GetLatLongFromAddress(locationString);
     return point;
 }
Пример #12
-1
        public async Task AddShopAsync(ClaimsPrincipal user, ShopViewModel shopViewModel)
        {
            Shop shop = new Shop();

            var addressData = new AddressData
            {
                Address = shopViewModel.Address,
                City = shopViewModel.City.ToUpper(),
                Country = "Italy"
            };

            var gls = new GoogleLocationService();
            var latlong = gls.GetLatLongFromAddress(addressData);
            var latitude = latlong.Latitude;
            var longitude = latlong.Longitude;

            shop.Name = shopViewModel.Name;
            shop.ShortDesc = shopViewModel.ShortDesc;
            shop.City = shopViewModel.City;
            shop.Address = shopViewModel.Address;
            shop.Website = shopViewModel.Website;
            shop.Phone = shopViewModel.Phone;
            shop.Latitude = latitude;
            shop.Longitude = longitude;
            shop.InsertDate = DateTime.Now;
            shop.InsertUserId = user.GetUserId();
            shop.UserId = user.GetUserId();

            _dbContext.Shop.Add(shop);

            await _dbContext.SaveChangesAsync();

        }
 public static void ClassInitialize()
 {
     if (Common.VersionInfo[0] < 3 || Common.VersionInfo[1] < 2)
     {
         Assert.Ignore($"Geospatial tests ignored for version {string.Join(".", Common.VersionInfo)}\n");
     }
     _locationSvc = new GoogleLocationService();
     _coordZapopan = _locationSvc.GetLatLongFromAddress("Zapopan").ToGeoCoord();
     _coordLondon = _locationSvc.GetLatLongFromAddress("London").ToGeoCoord();
 }
Пример #14
-1
 public MapPoint GetLatLong(string address)
 {
     if (address == "") return null;
     try
     {
         var locationService = new GoogleLocationService();
         return locationService.GetLatLongFromAddress(address);
     }
     catch (Exception) { }
     return null;
 }