HTML and CSS Reference
In-Depth Information
file by reading the IP address that made the HTTP request, doing the IP-to-location
translation on the server side, and then outputting the results.
In addition to latitude and longitude, the location data shown in Table 8-1 is available.
Table 8-1. Location data examples from MaxMind geoip.js
Method
Description
Example data
geoip_country_code()
Country Code
US
geoip_country_name()
Country Name
United States
geoip_city()
City
Minneapolis
geoip_region_name()
Region
MN
geoip_region_name()
Region Name
Minnesota
geoip_postal_code()
Postal Code
55401
geoip_area_code()
Telephone Area Code
612
geoip_metro_code()
Metro Code
613
The free version of MaxMind requires attribution in the form of a link back to the
website, so the isMaxMind parameter has been added to the printLatLong() function to
indicate that MaxMind was used to get the location:
function printLatLong(latitude, longitude, isMaxMind) {
$('body').append('<p>Lat: ' + latitude + '</p>');
$('body').append('<p>Long: ' + longitude + '</p>');
// if we used MaxMind for location, add attribution link
if (isMaxMind) {
$('body').append('<p><a href="http://www.maxmind.com" target="_blank">IP
to Location Service Provided by MaxMind</a></p>');
}
}
Another scenario to be mindful of is if the user denies your request for
location information or something else goes wrong. To handle this
eventuality, set up the geo_error handler to also fall back to using IP-
to-location translation, as shown in the next recipe.
Because we've added MaxMind as a fallback, this solution is able to handle a larger
percentage of browsers and devices without having to rely on native geolocation sup-
port in the browser.
See Also
MaxMind provides free/open source geolocation solutions for city, country, and IP
lookups at http://www.maxmind.com/app/ip-location .
 
Search WWH ::




Custom Search