Example #1
0
        public async Task <LocationCoordinates> FindLocationCoordinates(string location)
        {
            var geocoder = new ForwardGeocoder();
            var request  = new ForwardGeocodeRequest
            {
                queryString = location,
                BreakdownAddressElements = true,
                ShowExtraTags            = false,
                ShowAlternativeNames     = false,
                ShowGeoJSON = false
            };

            var result = await geocoder.Geocode(request);

            var response = result.FirstOrDefault();

            if (result.Length > 0 && response != null)
            {
                return(new LocationCoordinates
                {
                    Latitude = response.Latitude,
                    Longitude = response.Longitude
                });
            }

            return(null);
        }
Example #2
0
        public async Task <ICollection <MapDataDto> > GetAtmLocations(ICollection <ATM> atms)
        {
            var t       = new ForwardGeocoder();
            var atmData = new List <MapDataDto>(atms.Count);

            foreach (var atm in atms)
            {
                var request = new ForwardGeocodeRequest()
                {
                    queryString  = atm.Address,
                    LimitResults = 1
                };
                var response = await t.Geocode(request);

                MapLocation location = null;
                if (response.Length > 0)
                {
                    location = new MapLocation()
                    {
                        Latitude  = response[0].Latitude,
                        Longitude = response[0].Longitude
                    };
                }

                var tmp = new MapDataDto
                {
                    Atm      = atm,
                    Location = location
                };
                atmData.Add(tmp);
            }

            return(atmData);
        }
        public static GeocodeResponse GetAdressDetails(string query)
        {
            ForwardGeocoder       geocoder = new ForwardGeocoder();
            ForwardGeocodeRequest request  = new ForwardGeocodeRequest()
            {
                queryString  = query,
                LimitResults = 1,
                ShowGeoJSON  = true
            };
            var geocodeResponses = geocoder.Geocode(request);

            geocodeResponses.Wait();
            return(geocodeResponses.Result == null ? null : geocodeResponses.Result[0]);
        }
Example #4
0
        /// <summary>
        /// Esta funcion busca a traves de las direccion proporcionada por el objeto LocalizadorData
        /// la latitud y la longitud de dicha direccion.
        /// </summary>
        /// <param name="LD"></param>
        /// <returns>LD</returns>
        public static LocalizadorData Find(LocalizadorData LD)
        {
            ForwardGeocodeRequest d = new ForwardGeocodeRequest();
            GeocodeResponse       g = new GeocodeResponse();

            d.City          = LD.ciudad;
            d.Country       = LD.pais;
            d.StreetAddress = LD.calle + " " + LD.numero.ToString();
            d.County        = LD.provincia;
            ForwardGeocoder          FG = new ForwardGeocoder();
            Task <GeocodeResponse[]> r  = FG.Geocode(d);

            g           = r.Result[0];
            LD.latitud  = g.Latitude;
            LD.longitud = g.Longitude;
            return(LD);
        }
Example #5
0
        static async Task <Coordinates> GetCoordinatesAsync(string query)
        {
            var geocoder = new ForwardGeocoder();
            var request  = new ForwardGeocodeRequest()
            {
                queryString = query
            };

            var result = await geocoder.Geocode(request);

            if (result.Length > 0)
            {
                var geocodeResponse = result.First();
                var tags            = geocodeResponse.ExtraTags;
                return(new Coordinates(geocodeResponse.Latitude, geocodeResponse.Longitude));
            }
            return(null);
        }
Example #6
0
        private Dictionary <string, string> buildQueryString(ForwardGeocodeRequest r)
        {
            var c = new Dictionary <string, string>();

            // We only support JSON
            c.AddIfSet("format", format);
            c.AddIfSet("key", key);

            if (r.queryString.hasValue())
            {
                c.Add("q", r.queryString);
            }
            else
            {
                c.AddIfSet("street", r.StreetAddress);
                c.AddIfSet("city", r.City);
                c.AddIfSet("county", r.County);
                c.AddIfSet("state", r.State);
                c.AddIfSet("country", r.Country);
                c.AddIfSet("postalcode", r.PostalCode);
            }

            if (r.ViewBox != null)
            {
                var v = r.ViewBox.Value;
                c.Add("viewbox", $"{v.minLongitude},{v.minLatitude},{v.maxLongitude},{v.maxLatitude}");
            }

            c.AddIfSet("bounded", r.ViewboxBoundedResults);
            c.AddIfSet("addressdetails", r.BreakdownAddressElements);
            c.AddIfSet("limit", r.LimitResults);
            c.AddIfSet("accept-language", r.PreferredLanguages);
            c.AddIfSet("countrycodes", r.CountryCodeSearch);
            c.AddIfSet("namedetails", r.ShowAlternativeNames);
            c.AddIfSet("dedupe", r.DedupeResults);

            c.AddIfSet("polygon_geojson", r.ShowGeoJSON);
            c.AddIfSet("polygon_kml", r.ShowKML);
            c.AddIfSet("polygon_svg", r.ShowSVG);
            c.AddIfSet("polygon_text", r.ShowPolygonText);
            c.AddIfSet("extratags", r.ShowExtraTags);

            return(c);
        }
Example #7
0
        public Message Buscar(Message msg)
        {
            ForwardGeocodeRequest FGR     = new ForwardGeocodeRequest();
            GeocodeResponse       request = new GeocodeResponse();

            try
            {
                FGR.City          = msg.ciudad;
                FGR.Country       = msg.pais;
                FGR.StreetAddress = msg.calle + " " + msg.numero.ToString();
                FGR.County        = msg.provincia;
                ForwardGeocoder          FG       = new ForwardGeocoder();
                Task <GeocodeResponse[]> response = FG.Geocode(FGR);
                request      = response.Result[0];
                msg.latitud  = request.Latitude;
                msg.longitud = request.Longitude;
            }
            catch (Exception ex)
            {
                var error = ex.Message;
            }

            return(msg);
        }
Example #8
0
        /// <summary>
        ///     Attempt to get coordinates for a specified query or address.
        /// </summary>
        /// <param name="req">Geocode request object</param>
        /// <returns>Array of geocode responses</returns>
        public async Task <GeocodeResponse[]> Geocode(ForwardGeocodeRequest req)
        {
            var result = await WebInterface.GetRequest <GeocodeResponse[]>(url, buildQueryString(req)).ConfigureAwait(false);

            return(result);
        }