Combining Maxmind GeoIP with Google Maps iFrame

0
315

This is a quick script which uses Maxminds geoip location db downloadable for free from here with Google Maps iFrame. I haven’t tested this enough to find out if Google restrict the number of requests by referrer but you could always put a meta refresh page in the iframe to blank the referrer if thats a problem.

<?php
// you might have to change the first three lines
$gpath = getcwd() . "/geoip/GeoIPCity.dat"; // to where your db is
$myip=$_SERVER['HTTP_X_FORWARDED_FOR']; // to 'HTTP
include("geoip/geoipcity.inc");  // to where your .inc file is
$gi = geoip_open($gpath,GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,$myip);
$city = $record->city;
$lat = $record->latitude;
$long = $record->longitude;
$countrycode = $record->country_code;
geoip_close($gi);
?>
<html>
<head>
</head>
<body>
<iframe frameborder="0" marginwidth="0" marginheight="0" border="0" style="border:0; margin:0; width:340px; height:200px; -moz-border-radius: 15px; border-radius: 15px; border:3px solid #F00;" src="http://www.google.com/uds/modules/elements/mapselement/iframe.html?maptype=hybrid&amp;latlng=<?php echo $lat; ?>%2C<?php echo $long; ?>" scrolling="no" allowtransparency="true"></iframe>
</body>
</html>

LEAVE A REPLY

Please enter your comment!
Please enter your name here