public async Task ReverseGeocode() { var results = await WorldGeocoder.ReverseGeocodeAsync(GeometryHelpers.FromLatLong(34.05722922814357, -117.1956764921524)); var address = results[0].Label; Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0); var result = results[0]; Assert.IsTrue(result.Label.Contains("New York St"), $"Expected '*New York St*', but got {result.Label}"); }
public async Task GetAddress() { var results = await WorldGeocoder.GeocodeAsync("380 New York St, Redlands, CA"); var location = results[0].DisplayLocation; Assert.IsNotNull(results); Assert.IsTrue(results.Count > 0); var result = results[0]; Assert.AreEqual(-117.1956764921524, result.RouteLocation.X, 0.000001); Assert.AreEqual(34.05722922814357, result.RouteLocation.Y, 0.000001); Assert.AreEqual(4326, result.RouteLocation.SpatialReference.Wkid); }
private void _CreateGeocoder() { GeocodingServiceInfo currentGeocodingServiceInfo = null; for (int index = 0; index < _servicesInfo.GeocodingInfo.GeocodingServiceInfo.Length; index++) { GeocodingServiceInfo geocodingServiceInfo = _servicesInfo.GeocodingInfo.GeocodingServiceInfo[index]; if (geocodingServiceInfo.current) { if (currentGeocodingServiceInfo != null) { throw new ApplicationException(Properties.Resources.DefaultGeocodingInfoIsNotUnique); } currentGeocodingServiceInfo = geocodingServiceInfo; } var isStreetsGeocoder = string.Equals( geocodingServiceInfo.type, STREETS_GEOCODER_TYPE, StringComparison.OrdinalIgnoreCase); if (isStreetsGeocoder && this.StreetsGeocoder == null) { var streetsGeocoderServer = _GetCurrentGcServer(geocodingServiceInfo); var streetsGeocoder = new Geocoder(geocodingServiceInfo, streetsGeocoderServer, _exceptionHandler); this.StreetsGeocoder = streetsGeocoder; } } // Detect that geocoder type is ArcGisGeocoder. var isArcGisGeocoder = string.Equals( currentGeocodingServiceInfo.type, ARCGIS_GEOCODER_TYPE, StringComparison.OrdinalIgnoreCase); var isWorldGeocoder = string.Equals( currentGeocodingServiceInfo.type, "WorldGeocoder", StringComparison.OrdinalIgnoreCase); // If it is arcgis geocoder - create it and use as default. if (isArcGisGeocoder) { AgsServer geocodeServer = _GetCurrentGcServer(currentGeocodingServiceInfo); _geocoder = new ArcGiscomGeocoder(currentGeocodingServiceInfo, geocodeServer, _exceptionHandler); this.StreetsGeocoder = _geocoder; } else if (isWorldGeocoder) { var worldGeocoder = WorldGeocoder.CreateWorldGeocoder( currentGeocodingServiceInfo, _exceptionHandler); _geocoder = worldGeocoder; this.StreetsGeocoder = worldGeocoder; } else { AgsServer geocodeServer = _GetCurrentGcServer(currentGeocodingServiceInfo); _geocoder = new Geocoder(currentGeocodingServiceInfo, geocodeServer, _exceptionHandler); } if (this.StreetsGeocoder == null) { this.StreetsGeocoder = _geocoder; } }