NOTE: This is currently broken, since I upgrade wordpress, seemingly due to the MIME plugin not working. Hopefully I’ll get round to fixing it. (either the page or the plugin). I should probably be doing this differently anyway.
My first “mashup”! It should geolocate your IP (using GeoIP from MaxMind), and then display a Google map of the approximate location. Note this is a proper google map you can move around and stuff. Since it’s a free version of the database, it’s sadly lacking, and may well just think you are in the middle of Kansas.
)
Technically not really a mashup, since it only uses one web service (the IP lookup is hosted server-side, using the free database), but I’m going to count it. It took maybe an hour of fiddling with paths and suchlike to get something to appear. It’s the first PHP I’ve “written”.
Wordpress needed a bit of tweaking to get it to work, basically needing the runPHP plugin, and the Mime plugin. Not for the technically challenged. Before I forget what I did, I should write how it works
Step 1: download the files geoip.inc, geoipcity.inc and geoipregionvars.php from: http://www.maxmind.com/download/geoip/api/php/, I stuck them in folder /geo
Step 2: download the GeoLiteCity binary database, http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz, and stick it in the same place (or wherever, see later).
Step 3: The code you need to get latitude and longitude from an IP address is:
include("/your/absolute/path/geo/geoipcity.inc");
$gi = geoip_open("/your/absolute/path/geo/GeoLiteCity.dat",GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,getenv('REMOTE_ADDR'));
print $record->latitude . ",";
print $record->longitude . "\n";
geoip_close($gi);
So all you need to do is stick that code (between <?php and ?>) where the latitude and longitude are in the sample the Google gives you when you sign up for the Google Maps API. Oh, and note the “/your/absolute/path/” will need changing appropriately.
There you go. It’s a nasty hack and I’ll tidy it up later. I think the first thing would be figuring out how to set document variable in PHP, so I can use the $record results in more than one place.









I’m having problems getting this to work on my site http://www.allaboutmypc.com. Any idea what I’m doing wrong?
I went to your site and it looks like it’s kind of working, although it’s showing a different location for me - a bit more accurate, did you get the full database?
What is the problem you are having?
Funny that I just got out of this field.
For the last year and a half I had been working for a GIS web app development contracting firm. From my experience I can tell you:
-A) Google’s mapping abilities are very poor compared to commercial map renderers,
-B) writing even a passable map renderer is easy-peasy if you know anything about CG,
-C) commercial map renderers are slow for no good reason (related to B)
-D) the US Census just *gives* away a ton of data in a relatively easily consumable format that few people are even aware of,
-E) relational databases are too slow to ever make nice mapping,
-F) commercial map renderers are all built on relational databases, even the so-called “spatial” databases are really just relational databases with a few new Functions.
The field of GIS software has been driven almost completely by GIS analyst/n00b VB programmers and everyone’s favorite pointy-haired managers. God help the world if the field figures out how to pay Computer Scientists and Software Engineers a fair wage.
If I were you, I would dump Google like a sack of rotten potatoes. I doubt Google even employs anyone that would do this project well. MS has their local.live mapping that is marginally better than Google’s, but not by much. There is huge opportunity to do good stuff in this field, it’s just gotta be redone from the ground up. The problem is, the people that could do well in GIS are making 5 to 7 times as much in straight-up CG.