Posts

Showing posts from May, 2014

Creating a simple factory for objects with a fluent configuration API

Image
When I recently came to writing a new component for a system I thought, "I love using fluent configuration in other libraries so I'm going to write this with a fluent configuration API!". Of course, as with most projects, I made a lot of mistakes and had to keep going back and rewriting it from the ground up. I also wasn't able to find a lot of examples/discussion on creating fluent APIs for configuration so I decided to write a simple example that isn't really useful in itself but is useful as a learning exercise (at least it was for me!) I decided to put the full source on Github  rather than uploading a zip as I find downloading examples as a zip annoying! The whole idea for the example was to have a simple way of creating a factory object that is able to create objects of a certain type according to some configured rules. To make life easier, I added a constraint to only allow objects with a parameterless constructor. Or to put it another way: ...

Using Google for geocoding without displaying a map

Image
In a previous blog post  I talked about performance tuning SQL queries involving Geographies. In order to use the (now much faster) queries we needed a way of reliably getting a user's approximate location in order to figure out where they were and what the most appropriate content for them is based on that location. Originally, I thought about using the google.maps.Geocoder but I didn't really want to show a map on our UI - a requirement of using the Geocoder as mentioned in Google's ToS. While looking for alternatives, I stumbled across the places auto complete. It's full of juicy goodness, it's easy to use and the documentation even says: You can use Place Autocomplete even without a map. If you do show a map, it must be a Google map. Yay! Here's a screenshot from the documentation: Out of the box it doesn't work exactly as I wanted. I need it to only show results for a certain country and I'm only interested in lat long - I don't...