Exemplo n.º 1
0
        private BingMapsDataSources LiveMapsDataSource(string country)
        {
            BingMapsDataSources bingMapsDataSource = BingMapsDataSources.World;

            if (string.IsNullOrEmpty(country))
            {
                // It happens
            }
            else if (this.eucountries.Contains(country.ToLower()))
            {
                bingMapsDataSource = BingMapsDataSources.EU;
            }
            else if (this.nacountries.Contains(country.ToLower()))
            {
                bingMapsDataSource = BingMapsDataSources.NA;
            }
            else if (this.apcountries.Contains(country.ToLower()))
            {
                bingMapsDataSource = BingMapsDataSources.AP;
            }
            else if (country.ToLower() == "brazil")
            {
                bingMapsDataSource = BingMapsDataSources.BR;
            }

            return(bingMapsDataSource);
        }
Exemplo n.º 2
0
        public Fotofly.Address FindAddress(GpsPosition gpsPosition, string country, bool useCache)
        {
            Fotofly.Address returnValue = new Fotofly.Address();

            // Check Resolver Cache
            if (this.resolverCache != null && useCache)
            {
                returnValue = this.resolverCache.FindAddress(gpsPosition);

                if (returnValue != null && returnValue.IsValidAddress)
                {
                    return(returnValue);
                }
            }

            // Reset incase null from above
            returnValue = new Fotofly.Address();

            // Set the LatLong
            LatLong latLong = new LatLong();

            latLong.Latitude  = gpsPosition.Latitude.Numeric;
            latLong.Longitude = gpsPosition.Longitude.Numeric;

            // Set the datasource
            BingMapsDataSources dataSource = this.LiveMapsDataSource(country);

            GetInfoOptions options = new GetInfoOptions();

            options.IncludeAddresses      = true;
            options.IncludeAllEntityTypes = false;

            GetLocationInfoRequest infoRequest = new GetLocationInfoRequest();

            infoRequest.dataSourceName = "MapPoint." + dataSource.ToString();
            infoRequest.options        = options;
            infoRequest.location       = latLong;

            Location[] places = null;

            try
            {
                places = this.findService.GetLocationInfo(null, null, latLong, infoRequest.dataSourceName, options);
            }
            catch (EndpointNotFoundException e)
            {
                throw new Exception("Unable to find\\connect to Bing Map WebService", e);
            }
            catch (TimeoutException e)
            {
                throw new Exception("Bing Map call timed out", e);
            }
            catch (Exception e)
            {
                places = null;
            }

            if (places != null && places.Length > 0 && places[0].Address != null)
            {
                returnValue.Country     = places[0].Address.CountryRegion;
                returnValue.Region      = this.LookupRegionName(places[0].Address.Subdivision, returnValue.Country);
                returnValue.City        = places[0].Address.PrimaryCity;
                returnValue.AddressLine = places[0].Address.AddressLine;
            }
            else
            {
                // Add to Failure to cache
                if (this.resolverCache != null)
                {
                    this.resolverCache.AddToReverseFailedRecords(gpsPosition);
                }
            }

            return(returnValue);
        }
Exemplo n.º 3
0
        public GpsPosition FindGpsPosition(Fotofly.Address addressToLookup, bool useCache)
        {
            GpsPosition returnValue = new GpsPosition();

            // Check Resolver Cache
            if (this.resolverCache != null && useCache)
            {
                returnValue = this.resolverCache.FindGpsPosition(addressToLookup);

                if (returnValue != null && returnValue.IsValidCoordinate)
                {
                    return(returnValue);
                }
            }

            BingMapsDataSources dataSource = this.LiveMapsDataSource(addressToLookup.Country);

            if (this.failedLookups.Contains(addressToLookup.HierarchicalName))
            {
                Debug.WriteLine("BingMapsResolver: " + addressToLookup.HierarchicalName + ": Address skipped (Previous Failed Lookup)");
            }
            else if (dataSource == BingMapsDataSources.World)
            {
                Debug.WriteLine("BingMapsResolver: " + addressToLookup.HierarchicalName + ": Address skipped (World Maps does not support Reverse Geotagging)");
            }
            else
            {
                // Set up the address
                BingMaps.Address address = new BingMaps.Address();
                address.AddressLine   = addressToLookup.AddressLine;
                address.PostalCode    = string.Empty;
                address.PrimaryCity   = addressToLookup.City;
                address.Subdivision   = addressToLookup.Region;
                address.CountryRegion = addressToLookup.Country;

                if (string.IsNullOrEmpty(addressToLookup.City))
                {
                    address.PrimaryCity = addressToLookup.Region;
                    address.Subdivision = string.Empty;
                }

                // Set up the specification for the address
                // Set up the specification object.
                FindAddressSpecification findAddressSpec = new FindAddressSpecification();
                findAddressSpec.InputAddress = address;

                // More info: http://msdn2.microsoft.com/en-us/library/ms982198.aspx and http://msdn2.microsoft.com/en-us/library/aa493004.aspx
                findAddressSpec.DataSourceName = "MapPoint." + dataSource.ToString();

                // Set the find options. Allow more return values by decreasing
                // the count of the ThresholdScore option.
                // Also, limit the number of results returned to 20.
                FindOptions myFindOptions = new FindOptions();
                myFindOptions.ThresholdScore   = 0.5;
                myFindOptions.Range            = new FindRange();
                myFindOptions.Range.StartIndex = 0;
                myFindOptions.Range.Count      = 1;
                findAddressSpec.Options        = myFindOptions;

                FindAddressRequest addressRequest = new FindAddressRequest();
                addressRequest.specification = findAddressSpec;

                // Create a FindResults object to store the results of the FindAddress request.
                FindResults  myFindResults;
                FindResult[] myResults;

                try
                {
                    // Get the results and return them if there are any.
                    myFindResults = this.findService.FindAddress(null, null, findAddressSpec);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("BingMapsResolver: " + addressToLookup.HierarchicalName + ": Call failed, error = " + e.ToString());

                    returnValue   = new GpsPosition();
                    myFindResults = null;
                }

                if (myFindResults != null)
                {
                    myResults = myFindResults.Results;

                    if (myResults != null && myResults.Length != 0)
                    {
                        returnValue = new GpsPosition();
                        returnValue.Latitude.Numeric  = myResults[0].FoundLocation.LatLong.Latitude;
                        returnValue.Longitude.Numeric = myResults[0].FoundLocation.LatLong.Longitude;
                        returnValue.Source            = BingMapsResolver.SourceName;

                        Debug.WriteLine("BingMapsResolver: " + addressToLookup.HierarchicalName + ": LatLong retrieved");
                    }
                    else
                    {
                        // Add to Failure to cache
                        if (this.resolverCache != null)
                        {
                            this.resolverCache.AddToForwardFailedRecords(addressToLookup);
                        }

                        // Add the failed resolution to the avoid list
                        this.failedLookups.Add(addressToLookup.HierarchicalName);

                        Debug.WriteLine("BingMapsResolver: " + addressToLookup.HierarchicalName + ": Address not found");

                        returnValue = new GpsPosition();
                    }
                }
            }

            return(returnValue);
        }