Compress location lookup using gzip.

This commit introduces optional compression of the location lookups. Some code cleanup for elements shared between lookup and uploading.

Closes #446.

Todo: move most of the communication code into NetworkUtils.