One recent project I’ve been working on involves dropping pins on a map of the world at locations that correspond to Google geolocation (longitude/latitude) coordinates. This seemed like a simple problem that I could find a thousand and one tutorials for, but turned out to be rather tricky – and I never did find a clear explanation of the process anywhere. So here’s a (hopefully) straightforward method for converting Google geo coordinates to pixel locations on a map image. We have a large set of location data that has been geocoded from postal code and country to Google-provided longitude and latitude using Geokit: We also have a world map image. Wikimedia Commons has quite a few blank world maps – the key is that we need to know what projection was used to make our map. Fortunately, a number of the maps on Wikimedia Commons list what projection was used, so in this case we have a map that was made using a “Miller cylindrical projection”: It turns out that longitude and latitude aren’t quite as universal as I thought before starting this project. Turning a location on the earth into a pair of numbers depends on the projection used to map the surface of the earth onto a flat plane. Google uses a particular projection to do this – and I would imagine each provider you can use with Geokit has their own special projection, different in some important (to those who know about GIS) or arbitrary (to someone like me who hasn’t got a clue about GIS) way from any of the others. Well, whatever – this is where the Proj.4 library comes in. Proj.4 is a library that can convert between different projection systems – where each projection system can be described by a Proj.4 configuration string – there’s even a massive directory that includes these Proj.4 configuration strings for each projection system. Since we have our longitude and latitude in Google’s projection system, we are going to use Proj.4 to translate to the Miller projection that matches our map image. If you are installing this on OS X, you’ll need to port install proj, and you will likely need to install the gem manually with: gem install proj4rb — –with-proj-dir=/opt/local/var/macports/software/proj/4.7.0_0/opt/local/ On debian-based systems, apt-get install proj and gem install proj4rb (or bundle install, etc) will get you there. First, we need the Proj.4 parameters for Google’s projection. Spatial Reference has us covered, just click the Proj4 link on this page, and you’ll see the params we need: We are converting to a Miller cylindrical projection, so we’ll create an object for our target projection as well: The last step is to convert our Miller projection based longitude and latitude to actual pixel positions on our map. I believe there may be a way to do this with Proj.4, but I had some trouble finding it, and it turns out it isn’t so hard – but we need to know a couple pieces of information: If you were lucky, the center point of the map image you are using may have been listed along with its projection system (typically it is in the ocean just south of the western part of Africa) – in this case I used some trial and error to adjust it by a few pixels so a sampling of cities around the world showed up in the correct spots. Armed with these constants describing the world map image we picked, we can do our final conversion (thanks to some random C# code): There we have it – a pretty simple process, all told – and we can now place our pins on the map. Here’s an example of this in action. Source.