Koddi Releases Scala Geocoding Library

Today Koddi is excited to announce the initial release of our own Scala Geocoding library. Here at Koddi, we value open source projects that allow small organizations to grow quickly and hope this project can return the favor for other developers out there!

A few may be asking why we chose to write our own library for something as simple as Geocoding. When we were researching libraries to use, we noticed a lack of high-quality Scala geocoding libraries. There are some available, but most of them never really caught our eye, so we set out to write a clean, lightweight library that any Scala programmer can use.

Before building the library, we had some clear-cut objectives: No 3rd-party dependencies, fully tested, compliant with the Google Geocoding API including tertiary parameters, and easy enough to use that developers would want to adopt this library. The Koddi Geocoder accomplishes all of these goals and some additional features we were able to roll in afterward. Let’s dive in and take a look at some usage examples.

Importing and creating the Geocoder:

In the above example, we create a Geocoder object and then perform an address lookup — in just 3 lines of code! Geocoder can be created in different ways. Refer to the documentation for creating a Geocoder with an API key or extra parameters.

Next let’s look at accessing the results. All results are returned as a Seq[Result]. We have built the Result class to match the Google Geocoding XML response payload. In most cases, you will just need to access the first location data set (if you are trying to get the latitude/longitude values). To see all available fields within a Result object refer to the documentation.

Looking up latitude/longitude by address value:

In addition to looking up location data by a street address, you can also query locations by latitude/longitude, components, and place IDs. Note: Place IDs require that an API key or Client ID be sent with the request.

Lastly, we wanted to touch on asynchronous usage. The Koddi Geocoder library supports asynchronous usage to use it just create an AsyncGeocoder. All methods are the same as Geocoder, however they will return a Future[Seq[Result]] instead of a Seq[Result].

Performing an asynchronous lookup:

In the above example, we create an asynchronous client and look up a formatted address. The future will return onSuccess when the location data is received. Otherwise, all errors will bubble up to onFailure.

If you are interested in trying out the library, we recommend heading over to Github and cloning it down. The repository link can be found below. We are always on the lookout for new bugs and improvements.

Github Repository:
https://github.com/KoddiDev/geocoder

Happy coding!

Categories
Technology