{"id":106,"date":"2011-03-04T18:30:52","date_gmt":"2011-03-04T18:30:52","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=106"},"modified":"2011-03-04T18:32:28","modified_gmt":"2011-03-04T18:32:28","slug":"country-city-state-location-ip-address","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/country-city-state-location-ip-address\/","title":{"rendered":"Country, City, State and Other location information from IP Address"},"content":{"rendered":"<p>If you wish to determine a remote visitor&#39;s country, city, state, postal code and other location information, I&#39;d personally recommend integrating with a web service which maintains a current database.<\/p>\n<p>Our service of choice is <a class=\"target-blank\" href=\"http:\/\/www.maxmind.com\/app\/city\">MaxMind&#39;s GeoIP Web Service<\/a>.<\/p>\n<p>Integration is a snap with a simple HTTP GET request. ColdFusion example code is provided below:<\/p>\n<p><code>&lt;cffunction name=&quot;locationInfo&quot; access=&quot;public&quot; output=&quot;false&quot; returntype=&quot;struct&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfset locationDict = StructNew()&gt;<\/p>\n<p>\t&nbsp;&nbsp;&nbsp; &lt;cftry&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset ip = cgi.REMOTE_HOST&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfhttp method=&quot;get&quot; url=&quot;geoip3.maxmind.com\/f?l=D90rjl5Oq9km&amp;i=#ip#&quot; result=&quot;info&quot;&gt;&lt;\/cfhttp&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset info = info.Filecontent&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.country = ListGetAt(info,1)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.state = ListGetAt(info,2)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.city = ListGetAt(info,3)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.postal = ListGetAt(info,4)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfcatch&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.country = &quot;&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.state = &quot;&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.city = &quot;&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset locationDict.postal = &quot;&quot;&gt;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/cfcatch&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/cftry&gt;<\/p>\n<p>\t&nbsp;&nbsp;&nbsp; &lt;cfreturn locationDict&gt;<br \/>\n\t&lt;\/cffunction&gt;<br \/>\n\t<\/code><\/p>\n<p>Note the error handling, which gracefully returns an empty string for all values, in the event the web service is down, or has change it&#39;s response format.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you wish to determine a remote visitor&#39;s country, city, state, postal code and other location information, I&#39;d personally recommend integrating with a web service&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[34,4],"tags":[45,46],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/106"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=106"}],"version-history":[{"count":2,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/106\/revisions"}],"predecessor-version":[{"id":108,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/106\/revisions\/108"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}