Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Find user location (Please help me fix below or suggest any other way)

New Here ,
Nov 15, 2014 Nov 15, 2014

Hi

Hopefully, some one can help me with this issue. I am trying to implement a global site and hence was looking for a way to detect user location. I do not want to use any ip2location webservice or download a database or ask for user to "share location".

Anyways, I found this project. I implemented it , it detects my location correctly (US). However for my friend in Germany it is returning an empty string for Country.

http://javainetlocator.sourceforge.net/. I am using jar file from here. http://sourceforge.net/projects/javainetlocator/files/ with version 2.23

I am using CF 11 and my code is on

http://roomdu.com/geolocator/

PLEASE SUGGEST ME

  <cfset ipAddress=cgi.REMOTE_ADDR>

       <cfset geoLocator=createobject("component","remoteClassPath_geoLocator")>

       <cfset Ok=geoLocator.init()>

    

              <cfset thisLocale=geoLocator.findLocale(ipAddress,cgi.HTTP_ACCEPT_LANGUAGE)>

              <cfset thisCountry=geoLocator.findCountry(ipAddress,cgi.HTTP_ACCEPT_LANGUAGE)>

              <cfset thisLanguage=geoLocator.findLanguage(ipAddress,cgi.HTTP_ACCEPT_LANGUAGE)>

              <cfset thisC=geoLocator.showCountry(ipAddress)>

              <cfset thisL=geoLocator.showLanguage(ipAddress)>

              <cfset bLocaleValid=geoLocator.isValidLocale("fr_RU")>

<cfif ok>

       <cfoutput>

       <b><h2>Not your grandmother's geoLocator Remote</h2></b>

       <hr align="left" width="30%">

       <b>geoLocator</b> := Initialized plenty fine.

       <br>

       <b>ip address</b> := #ipAddress#

       <br>

       <b>browser http_accept_language</b> := #cgi.HTTP_ACCEPT_LANGUAGE#

       <br>

       <b>This locale from geoLocator</b> := #thisLocale#

       <br>

       <b>This country (2 letter code) from geoLocator</b> := #thisCountry#

       <br>

       <b>This language (2 letter code) from geoLocator</b> := #thisLanguage#

       <br>

       <b>This country from geoLocator</b> := #thisC#

       <br>

       <b>This language from geoLocator</b> := #thisL#

       <br>

       <b>Test fr_RU as valid locale</b> := #yesnoFormat(bLocaleValid)#

       </cfoutput>

       <br>

       <table cellspacing="1" cellpadding="1" width="300" height="210">

       <tr>

       <td valign="top" title="Flash World Map">

       <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"

        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"

        WIDTH="300" HEIGHT="200" id="world" ALIGN="">

        <PARAM NAME=movie VALUE="world.swf">

        <PARAM NAME=quality VALUE=high>

        <cfoutput><PARAM NAME='Flashvars' VALUE='country=#thisCountry#&colover=FFCC00&colsel=FF0000'></cfoutput>

        <PARAM NAME=bgcolor VALUE=#66CCFF>

        <EMBED src="world.swf" quality=high bgcolor=#66CCFF WIDTH="300" HEIGHT="200" NAME="world" ALIGN=""

        TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>

       </OBJECT>

       </td>

       </tr>

       <tr>

       <td style="{font-size : 9px;}">flash map provided by <a href="mailto:eric.mauviere@emc3.fr" style="{font-size : 9px;}">eric mauviere</a></td>

       </tr>

       </table>

<cfelse>

       Oops, poop hit the fan.

</cfif>

325
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2014 Nov 16, 2014
LATEST

Roomdu wrote:

Anyways, I found this project. I implemented it , it detects my location correctly (US). However for my friend in Germany it is returning an empty string for Country.

It may just be that the program returns a blank for certain IPs.  Broaden the test of your code. Collect a list of IPs situated in Germany and, for each, print out the value of

geoLocator.showCountry(ipAddress)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources