December 21, 2019

How to Reverse-Geocode Addresses for Free

I just added functionality to units to reverse-geocode addresses. My test method for this code follows:

 @Test
 public void geocodeWorks() {

  Map<String, String> expected = new Gson().fromJson(
    "[{\"request\":\"2017 North Beverly Glen Blvd, 
Los Angeles, CA 90077, USA\",\"displayName\":\"Emerging Market Services, 2017, 
North Beverly Glen Boulevard, Beverly Glen, Westwood, Los Angeles, Los Angeles 
County, California, 90077, United States of America\",\"latitude\":\"34.1056855
\",\"source\":\"\",\"longitude\":\"-118.4461788\"}]",
    new TypeToken<List<Map<String, String>>>() {
    }.getType());
  StringMap actual = this.restTemplate.postForObject("/geocode",
    Collections.singletonMap("addr",
      "2017 North Beverly Glen Blvd, 
Los Angeles, CA 90077, USA"),
    StringMap.class);
  Assert.assertEquals(expected, actual);
 }
There's no rate limit on this API (for now), so use it to your heart's content. And you can view the up-to-date test code, as they evolve here.

No comments:

Post a Comment