GeoLocation - javaQuery API

I've been working on my personal project. It needs to track down the visitors of website. I searched couple of query on Google but couldn't work for me so I created my own API to track down the users. I'm sharing this API with you guys. Please make note that I'm using open source website to track users but it allows you only 3000 request per day.

Now lets jump to code conclusion. Users already using javaQueryAPI 7.0 or less. I've made major changes in javaQueryAPI 8.0 so when you import new API keep in mind that you must change your existing code that uses javaQueryAPI.
/*
* javaQueryAPI 7.0 or less
*/
import javaQuery.j2ee.GeoLocation
request.getHeader("VIA");
String ipAddress = request.getHeader("X-FORWARDED-FOR");
       if (ipAddress == null) {
            ipAddress = request.getRemoteAddr();
       }
GeoLocation gl = new GeoLocation();
gl.GetGeoLocationByIP(ipAddress);
String country = gl.Country;

/*
* javaQueryAPI 8.0 or above
*/
import javaQuery.importClass.javaQueryBundle;
import javaQuery.j2ee.GeoLocation;

request.getHeader("VIA");
String ipAddress = request.getHeader("X-FORWARDED-FOR");
if (ipAddress == null) {
 ipAddress = request.getRemoteAddr();
}
GeoLocation $gl = javaQueryBundle.createGeoLocation();
$gl.MAPTargetByIP("117.204.232.104", "This is Demo. You can set even NULL");
System.out.println($gl.Latitude);
System.out.println($gl.Longitude);
System.out.println($gl.Country);
System.out.println($gl.City);
System.out.println($gl.State);
System.out.println($gl.GoogleMap_URL);
System.out.println($gl.GoogleMap_URL_Bubble);
   
/*
* output
* 23.0333
* 72.616699
* India
* Ahmedabad
* Gujarat
* http://maps.google.com/maps?q=23.0333,+72.616699+(117.204.232.104)&iwloc=A&hl=en
* http://maps.google.com/maps?q=23.0333,+72.616699+(This is Demo. You can set even NULL)&iwloc=A&hl=en
*/

Some of users facing that its not working. It won't work on local machine as it won't resolve the data for 127.0.0.1 . Upload your file on server and access page through any browser. I'm working on API that allows you to track the user location based on mobile information. I'll publish ASAP. till then happy coding.

Read the related Article :

Check out the http://www.javaquery.com/p/javaquery-api.html for download.

18 comments :

  1. Thanks for the API.
    The latitude and longitude detected are not very accurate. Is there any way to improve it ?

    ReplyDelete
  2. As you are programmer and you know that location of IP defer sometime. If they are using strong proxy we can't track perfect location. And for javaQuery API i used free service so location may not be perfect. And its not possible to get perfect Longitude-Latitude of device. If you are using mobile device. Which has GPS facilities thats the only way to get Latitude-Longitude accurate. Even google can't track your system's perfect location. This is the reason. Thank You...

    ReplyDelete
  3. when I upload this code to my hosting then I am not getting the city name, longitude & latitude, its only returning the IP address of my server not the IP of visitor.

    ReplyDelete
  4. http://www.javaquery.com/2011/12/how-to-get-visitors-ip-address-in-java.html Use this article..

    ReplyDelete
  5. @vicky: thanks for the link. With this the visitor IP is returning but I am not getting the city name, country name, latitude & longitude.

    ReplyDelete
  6. I have site in Java www.0signals.com and its running good with this API. Will you plz post your code snippet here.

    ReplyDelete
  7. <%@ page import="java.net.InetAddress" %>
    <%@ page import="java.net.UnknownHostException" %>
    <%@ page import="javaQuery.j2ee.GeoLocation" %>
    <%
    request.getHeader("VIA");
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
    if (ipAddress == null) {
    ipAddress = request.getRemoteAddr();
    }
    GeoLocation gl = new GeoLocation();
    gl.GetGeoLocationByIP(ipAddress);
    String IP = gl.IP;
    String Country = gl.Country;
    String City_Name = gl.City;
    String Latitude = gl.Latitude;
    String Longitude = gl.Longitude;
    %>

    ReplyDelete
  8. Are you testing on local system??? It won't give you details for IP 127.0.0.1. Try it on your server it works fine..

    ReplyDelete
  9. not running on server, I have used this code to my running website http://www.bazaardekho.com/test3.jsp

    & the code using in this page is just:

    <%@ page import="javaQuery.j2ee.GeoLocation" %>
    <%
    request.getHeader("VIA");
    String ipAddress = request.getHeader("X-FORWARDED-FOR");
    if (ipAddress == null) {
    ipAddress = request.getRemoteAddr();
    }
    GeoLocation gl = new GeoLocation();
    gl.GetGeoLocationByIP(ipAddress);
    String IP = gl.IP;
    String Country = gl.Country;
    String City_Name = gl.City;
    String Latitude = gl.Latitude;
    String Longitude = gl.Longitude;
    out.print("IP:"+IP+"
    ");
    out.print("Country:"+Country+"
    ");
    out.print("City name:"+City_Name+"
    ");
    out.print("Latitude:"+Latitude+"
    ");
    out.print("Longitude:"+Longitude+"
    ");
    %>

    ReplyDelete
  10. I uploaded javaQuery 1.0.jar again so please download it and let me know is it working or not. Will you send me your personal email on support@0signals.com asi want some other discussion with you. download latest API https://sourceforge.net/projects/javaqueryapi/files/javaQuery1.0/javaQuery%20Bundle/ and if problem still exist i'll help you to solve the problem.

    ReplyDelete
  11. hi

    My location is Chennai. But the program shows Bangalore. What could be the mistake in my lap

    ReplyDelete
  12. There is no fault in your lappy.Location of IP address depends on your service provider if they use strong proxy to hide location we can't determine the exact location.

    ReplyDelete
  13. http://www.javaquery.com/2011/12/how-to-get-visitors-ip-address-in-java.html

    ReplyDelete
  14. great work vicky........you are the guy bro....tanx..............

    ReplyDelete
  15. can u give me your email.........so i could consult u for further problems bro..............thanx

    ReplyDelete
  16. vkijust4u@javaquery.com | And thank you for the compliment...Plz Join Google+ if you are using....

    ReplyDelete
  17. Awesome.. Worked like a charm.. made my day :)

    ReplyDelete

Note: only a member of this blog may post a comment.