//----------------------------------------------------------------------
        private static IntSet <PartyId> SearchByCity(
            Timer t,
            AddressParserResult searchLocale,
            int desiredResultCount,
            int maxResultCount,
            double nonGeoMatchAbsDensity,
            out Location centroid,
            out double?maxRadiusMi)
        {
            maxRadiusMi = null;

            if (desiredResultCount == ExactMatchResultCount)
            {
                IntSet <PartyId> partiesInCity = null;
                t.Measure("Search by City", delegate() {
                    partiesInCity = Snap.Cache.Cache.City(searchLocale);
                });
                centroid = null;
                return(partiesInCity);
            }
            else
            {
                IGeoCoder geocoder = GeoCoderFactory.CreateGeoCoder();
                centroid = geocoder.GeoCode(
                    searchLocale.City,
                    searchLocale.StateCode);
                return(SearchNearLocation(
                           t,
                           desiredResultCount,
                           centroid,
                           nonGeoMatchAbsDensity,
                           out maxRadiusMi));
            }
        }
示例#2
0
        public ActionResult Geocode(string address)
        {
            if (String.IsNullOrEmpty(address))
            {
                return(View("Index"));
            }

            var addresses = geoCoder.GeoCode(address).ToArray();

            return(View("Index", addresses));
        }
        //----------------------------------------------------------------------
        private static IntSet <PartyId> SearchNearStreetAddress(
            Timer t,
            AddressParserResult searchLocale,
            int desiredResultCount,
            int maxResultCount,
            double nonGeoMatchAbsDensity,
            out Location centroid,
            out double?maxRadiusMi)
        {
            if (null == searchLocale.Location)
            {
                IGeoCoder  geocoder = GeoCoderFactory.CreateGeoCoder();
                Location[] ls       = geocoder.GeoCode(
                    searchLocale.StreetAddress,
                    searchLocale.City,
                    searchLocale.StateCode,
                    searchLocale.PostalCode);

                if (ls.Length == 0)
                {
                    throw new ArgumentException("unknown address");
                }

                if (ls.Length > 1)
                {
                    throw new ArgumentException("ambiguous address");
                }

                centroid = ls[0];
            }
            else
            {
                centroid = searchLocale.Location;
            }

            maxRadiusMi = null;
            return(SearchNearLocation(
                       t,
                       desiredResultCount,
                       centroid,
                       nonGeoMatchAbsDensity,
                       out maxRadiusMi));
        }
示例#4
0
 void IJob.Execute(IJobContext context, Operation operation)
 {
     // This is a Pre-Job. Thus it only has to run right after the operation has surfaced and before being stored.
     if (context.Phase == JobPhase.OnOperationSurfaced)
     {
         //Don't overwrite exisiting coordinates
         if (operation.Einsatzort.HasGeoCoordinates)
         {
             return;
         }
         GeocoderLocation geocoderLocation = _provider.GeoCode(operation.Einsatzort);
         if (geocoderLocation != null)
         {
             //The most of the widgets and so need the "english-format" (point instead of comma)!
             operation.Einsatzort.GeoLongitude = geocoderLocation.Longitude.ToString().Replace(',', '.');
             operation.Einsatzort.GeoLatitude  = geocoderLocation.Latitude.ToString().Replace(',', '.');
         }
         else
         {
             Logger.Instance.LogFormat(LogType.Error, this, "No coordinats found by geocoding service.");
         }
     }
 }
示例#5
0
 public void CanGeoCodeAddress()
 {
     Address[] addresses = geoCoder.GeoCode("1600 pennsylvania ave washington dc").ToArray();
     addresses[0].AssertWhiteHouse();
 }
示例#6
0
        public static Address ReadAddress(XmlReader addressReader, IGeoCoder geoCoder)
        {
            Address addr = new Address();

            addressReader.ReadToFollowing("Address");

            while (addressReader.Read())
            {
                if (addressReader.NodeType == XmlNodeType.Element)
                {
                    string elementName = addressReader.Name;

                    //Skip elements that have no text content. eg. <date/>
                    if (addressReader.IsEmptyElement)
                    {
                        continue;
                    }

                    //Reat to text content
                    addressReader.Read();

                    switch (elementName)
                    {
                        case "AddrLine":
                            {
                                addr.addrLine = addressReader.Value;

                                GeoCoding.Address[] addresses = geoCoder.GeoCode(addr.addrLine + "Toronto Canada");
                                if (addresses.Length != 0)
                                {
                                    addr.latCoord = addresses[0].Coordinates.Latitude;
                                    addr.longCoord = addresses[0].Coordinates.Longitude;
                                }

                                break;
                            }
                        case "House":
                            {
                                addr.houseNumber = addressReader.Value;
                                break;
                            }
                        case "Street":
                            {
                                addr.street = addressReader.Value;
                                break;
                            }
                        case "Type":
                            {
                                addr.streetType = addressReader.Value;
                                break;
                            }
                        case "Direction":
                            {
                                addr.streetDirection = addressReader.Value;
                                break;
                            }
                    }
                }
            }

            return addr;
        }