Exemplo n.º 1
0
 public GeoLocationService(TomTomApiService tomTomApiService, GoogleMapsApiService googleMapsApiService,
                           ILogger <GeoLocationService> logger)
 {
     TomTomApiService     = tomTomApiService;
     GoogleMapsApiService = googleMapsApiService;
     Logger = logger;
 }
Exemplo n.º 2
0
        public async Task <Point> GetGeoLocationFromApiAsync(Address address)
        {
            GeometryFactory geometryFactory = GetGeometryFactory();
            Point           geoLocation     = null;

            try
            {
                var googleResponse = await GoogleMapsApiService.GetLatLongAsync(address);

                HandleGoogleResult(googleResponse, googleResult =>
                {
                    geoLocation = geometryFactory.CreatePoint(new Coordinate(googleResult.Geometry.Location.Lng, googleResult.Geometry.Location.Lat));
                });
            }
            catch
            {
                try
                {
                    var tomTomResponse = await TomTomApiService.GetLatLongAsync(address);

                    HandleTomTomResult(tomTomResponse, tomTomResult =>
                    {
                        geoLocation = geometryFactory.CreatePoint(new Coordinate(tomTomResult.Position.Lon, tomTomResult.Position.Lat));
                    });
                }
                catch (Exception e)
                {
                    Logger.LogError("Sowohl Google Maps API als auch Tom Tom Api haben einen Fehler zurückgegeben. {exceptionMessage}", e.Message);
                    throw;
                }
            }
            return(geoLocation);
        }
Exemplo n.º 3
0
        public async Task <Address> FillOutAddressWithApiAsync(Address address)
        {
            GeometryFactory geometryFactory = GetGeometryFactory();

            try
            {
                var googleResponse = await GoogleMapsApiService.GetLatLongAsync(address);

                HandleGoogleResult(googleResponse, FillOutAddressWithGoogleMapsAction(address, geometryFactory));
            }
            catch
            {
                var tomTomResponse = await TomTomApiService.GetLatLongAsync(address);

                HandleTomTomResult(tomTomResponse, FillOutAddressWithTomTomAction(address, geometryFactory));
            }
            return(address);
        }
Exemplo n.º 4
0
        public async Task <IEnumerable <Address> > GetRelatedAddressesWithApiAsync(Address address)
        {
            try
            {
                var googleResponse = await GoogleMapsApiService.GetLatLongAsync(address);

                return(HandleGoogleResults(googleResponse));
            }
            catch
            {
                try
                {
                    var tomTomResponse = await TomTomApiService.GetLatLongAsync(address);

                    return(HandleTomTomResults(tomTomResponse));
                }
                catch (Exception e)
                {
                    Logger.LogError("Sowohl Google Maps API als auch Tom Tom Api haben einen Fehler zurückgegeben. {exceptionMessage}", e.Message);
                    throw;
                }
            }
        }