Package org.onebusaway.geocoder.model

Examples of org.onebusaway.geocoder.model.GeocoderResult


  @Test
  public void test() {

    GeocoderResults results = new GeocoderResults();

    GeocoderResult result = new GeocoderResult();
    result.setAddress("101 test blvd");
    result.setAdministrativeArea("wa");
    result.setCity("seattle");
    result.setCountry("usa");
    result.setLatitude(47.0);
    result.setLongitude(-122.0);
    result.setPostalCode("98000");
    results.addResult(result);

    GeocoderService mock = Mockito.mock(GeocoderService.class);
    Mockito.when(mock.geocode("test")).thenReturn(results);

    DatabaseCachingGeocoderImpl geocoder = new DatabaseCachingGeocoderImpl();
    geocoder.setSessionFactory(_sessionFactory);
    geocoder.setGeocoderService(mock);

    GeocoderResults resultsA = geocoder.geocode("test");
    List<GeocoderResult> resultsListA = resultsA.getResults();
    assertEquals(1, resultsListA.size());
    GeocoderResult resultA = resultsListA.get(0);

    assertEquals("101 test blvd", resultA.getAddress());
    assertEquals("wa", resultA.getAdministrativeArea());
    assertEquals("seattle", resultA.getCity());
    assertEquals("usa", resultA.getCountry());
    assertEquals(47.0, resultA.getLatitude(), 0.0);
    assertEquals(-122.0, resultA.getLongitude(), 0.0);
    assertEquals("98000", resultA.getPostalCode());

    GeocoderResults resultsB = geocoder.geocode("test");
    List<GeocoderResult> resultsListB = resultsB.getResults();
    assertEquals(1, resultsListB.size());
    GeocoderResult resultB = resultsListB.get(0);

    assertEquals("101 test blvd", resultB.getAddress());
    assertEquals("wa", resultB.getAdministrativeArea());
    assertEquals("seattle", resultB.getCity());
    assertEquals("usa", resultB.getCountry());
    assertEquals(47.0, resultB.getLatitude(), 0.0);
    assertEquals(-122.0, resultB.getLongitude(), 0.0);
    assertEquals("98000", resultB.getPostalCode());

    // Verify this happened only once, as the db should cache
    Mockito.verify(mock).geocode("test");
  }
View Full Code Here


  }

  @Override
  public GeocoderResults geocode(String location) {

    GeocoderResult result = new GeocoderResult();
    result.setLatitude(_lat);
    result.setLongitude(_lon);
    result.setAddress(_address);
    result.setCity(_city);
    result.setAdministrativeArea(_state);
    result.setPostalCode(_postalCode);
    result.setCountry(_country);

    GeocoderResults results = new GeocoderResults();
    results.addResult(result);
    return results;
  }
View Full Code Here

    GeocoderResults results = _geocoderService.geocode(location);
    List<GeocoderResult> records = results.getResults();

    if (records.size() == 1) {

      GeocoderResult result = records.get(0);

      // Store default search location for future sessions
      String name = _geocoderResultPresentationService.getGeocoderResultAsString(result);
      if( name == null || name.length() == 0)
        name = location;
      _searchLocationService.setDefaultLocationForCurrentUser(name, result.getLatitude(),
          result.getLongitude());
    }

    return results;
  }
View Full Code Here

TOP

Related Classes of org.onebusaway.geocoder.model.GeocoderResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.