GeoLocation - javaQuery API
UPDATED: 09 October 2011
Tags:
J2EE
,
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.
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.
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 :
- http://www.javaquery.com/2011/12/how-to-get-visitors-ip-address-in-java.html
- http://www.javaquery.com/2013/06/how-to-get-latitude-longitude-without.html
Check out the http://www.javaquery.com/p/javaquery-api.html for download.
Tags:
J2EE
,
javaQuery API
Thanks for the API.
ReplyDeleteThe latitude and longitude detected are not very accurate. Is there any way to improve it ?
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...
ReplyDeletewhen 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.
ReplyDeletehttp://www.javaquery.com/2011/12/how-to-get-visitors-ip-address-in-java.html Use this article..
ReplyDelete@vicky: thanks for the link. With this the visitor IP is returning but I am not getting the city name, country name, latitude & longitude.
ReplyDeleteI have site in Java www.0signals.com and its running good with this API. Will you plz post your code snippet here.
ReplyDelete<%@ page import="java.net.InetAddress" %>
ReplyDelete<%@ 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;
%>
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..
ReplyDeletenot running on server, I have used this code to my running website http://www.bazaardekho.com/test3.jsp
ReplyDelete& 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+"
");
%>
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.
ReplyDeletehi
ReplyDeleteMy location is Chennai. But the program shows Bangalore. What could be the mistake in my lap
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.
ReplyDeletehttp://www.javaquery.com/2011/12/how-to-get-visitors-ip-address-in-java.html
ReplyDeletegreat work vicky........you are the guy bro....tanx..............
ReplyDeletecan u give me your email.........so i could consult u for further problems bro..............thanx
ReplyDeletevkijust4u@javaquery.com | And thank you for the compliment...Plz Join Google+ if you are using....
ReplyDeleteAwesome.. Worked like a charm.. made my day :)
ReplyDeletethanks...
ReplyDelete