Showing posts with label javaQuery API. Show all posts

How to get Latitude - Longitude without GPS in mobile device?

radar

What is GPS?
GPS stands for Global Positioning System. Its a hardware used to get the accurate location of device. It gives the Latitude - Longitude of the device.

What if there ain't GPS?
You might used Google Maps in non GPS device. They are still able to get the perfect location of your device. So we'll look into that situation how they target the mobile device. All you need is get below details from mobile device.

1. Mobile Country Code (MCC) - To detect current country of device.
2. Mobile Network Code (MNC)- Te delete current service provide.
3. Local Area Code (LAC)- To detect device in which region.
4. Cell ID - Unique id of that region.

I created GeoLocation class in javaQuery API 8.1 . I'm using free service to get the latitude and longitude. Sometime you may get 0.0 for Latitude and Longitude. It says that there is no record available for that details. This API is for testing purpose. If you are creating the paid application or Official application, buy service to get the latitude and longitude using mcc, mnc, lac and cellid. Let's take a look at code snippet.
/*
 * MAPTargetByMobile(int, int, int, int);
 * MAPTargetByMobile(mcc, mnc, lac, cellid);
 * It'll only give you Latitude and Longitude
*/
import javaQuery.importClass.javaQueryBundle;
import javaQuery.j2ee.GeoLocation;

public class Demo {
    public static void main(String[] args) throws IOException{
        GeoLocation Target = javaQueryBundle.createGeoLocation();
        Target.MAPTargetByMobile(404, 58, 1339, 9029);
        System.out.println(Target.Latitude);
        System.out.println(Target.Longitude);
    }
}
Now what next? 
Use Google Maps to get location of mobile device using Latitude and Longitude.

Related Article:
How to create mobile tracking application? [http://www.javaquery.com/2011/09/how-to-create-mobile-tracking.html]

Validate the data for enterprise web applications.

 If you are web developer then you must validate some data. I did validation part easy for you guys. Check out the validate class in latest javaQuery API. Let me tell you what i included in new validation class.






  • Get file extension of any file
  • Validate the email
  • Remove html tags.
Check the below example that show the demo of the API:

import javaQuery.validation.validate;

public class RunCode {
    public static void main(String[] args) {
        validate _validateData = new validate();
        String strfile_Extension = "test.mp3";
        String strhtml_Data = "This test is bold";

        System.out.println("File extension: " + _validateData.getFileExtension(strfile_Extension));
        System.out.println("Email is: " + _validateData.Email("vkijust4u@javaquery.com"));
        System.out.println("HTML tag normalized: " + _validateData.removeHTML(strhtml_Data));
    }
}
Output : 
File extension: .mp3
Email is: true
HTML tag normalized: <b>This test is bold</b>
So now you don't need to write bunch of codes to validate the email address/ remove html tags and get the file extension of any file.

Developers : How to attach video in your website using java?

After long time I'm back to javaQuery article. Today m gonna show you how google+, Facebook, Twitter embed videos in there post, Tweet, etc... I was working on this code. This code will cover all video website like Youtube, vimeo, etc... that contains video information in proper formation. Check out the below code to demonstrate the URL. This library is present in latest javaQuery API. Some website may not be support by this API.



/*
* javaQueryAPI 7.0 or less
*/
import javaQuery.j2ee.EmbedVideo;
public class Video {
    public static void main(String[] args) {
        String WebVideo = "";
        EmbedVideo em = new EmbedVideo();
        boolean flag = em.EmbedVideo("http://www.youtube.com/watch?v=0N9JxHEoYd4");
        //flag will return true if website/link contains video details in proper format.
        if (flag) {
            System.out.println(EmbedVideo.provider_name);
            System.out.println(EmbedVideo.provider_url);
            System.out.println(EmbedVideo.author_name);
            System.out.println(EmbedVideo.author_url);
            System.out.println(EmbedVideo.title);
            System.out.println(EmbedVideo.description);
            System.out.println(EmbedVideo.html);
            System.out.println(EmbedVideo.width);
            System.out.println(EmbedVideo.height);
            System.out.println(EmbedVideo.thumbnail_url);
            System.out.println(EmbedVideo.video_url);
            System.out.println(EmbedVideo.xml_type);

            WebVideo = "Author:"+EmbedVideo.author_name;
            //Modify the Data as per your requirement like place the video in iframe
        }
    }
}
/*
* javaQueryAPI 8.0 or above
* This code requires additional JSON library. You must include JSON lib to work this API. Its available in javaQueryAPI 8.0/lib folder on sourceforge.net
*/
import javaQuery.importClass.javaQueryBundle;
import javaQuery.j2ee.embedvideo;

public class Demo {
    public static void main(String[] args) {
        embedvideo em = javaQueryBundle.create_embedvideo();
        em.linkTo("http://www.youtube.com/watch?v=SmM0653YvXU");
        System.out.println(em.title);
        System.out.println(em.video_url);
        System.out.println(em.description);
        System.out.println(em.width);
        System.out.println(em.height);
        System.out.println(em.thumbnail_url);
        System.out.println(em.author_name);
        System.out.println(em.author_url);
        System.out.println(em.html);
        System.out.println(em.provider_name);
        System.out.println(em.provider_url);        
    }
}
/*
* output
* Pitbull - Rain Over Me ft. Marc Anthony
* http://www.youtube.com/watch?v=SmM0653YvXU
* Not Available
* 480
* 270
* http://i4.ytimg.com/vi/SmM0653YvXU/hqdefault.jpg
* PitbullVEVO
* http://www.youtube.com/user/PitbullVEVO
* <iframe allowfullscreen="" frameborder="0" height="270" src="http://www.youtube.com/embed/SmM0653YvXU?feature=oembed" width="480"></iframe>
* YouTube
* http://www.youtube.com/
*/

Once you done with the code. You can change the properties of video attachment for your page. Change the video CSS, width, height.

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

How to get visitors IP address in Java?


This is tough task i searched around the Google , Tones of codes but after so many test i got the solution for this. This is very simple let me explain how you can get IP address of visitor. There is questions of programmers like "how to get client's IP Address in Java?"








  • I know you tried "request.getRemoteAddr()" but its not working and give you 127.0.0.1 as an output.
Sample code to get IP address

request.getHeader("VIA");
String ipAddress = request.getHeader("X-FORWARDED-FOR");
       if (ipAddress == null) {
            ipAddress = request.getRemoteAddr();
       }

This code works perfectly i tested it on my server. Now you have IP address but after that question is how to get Country, City, Latitude, Longitude using Java? This will be done by javaQuery API. For that u can try below code.

Important notice for existing user (javaQueryAPI 7.0 or less) : Please check the new changes in javaQueryAPI 8.0 before installing API in your project.

/*
* 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.

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

How to compress Image in Java?



In Java there is no specific API to compress image. You have to go through bunch of codes to compress an image as per preferred size. Here I came with API that helps you to compress image on single method call and yes this is part of our own javaQuery API.

Features:
  • Compress image online / offline
  • Compress image as per your preferred size.
  • Supported File : *.png, *.jpg
/*
 * Image Resize ir = new ImageResize();
 * ir.compressImage("FileLink","Saveas", width, height);
 *
 * Offline : C:\\test.JPG
 * Online : Servlet, Struts, etc... String FileLink = getServletContext().getRealPath("/Your_Dir/");
 */
import javaQuery.j2ee.ImageResize;

public class compressImage {
    public static void main(String[] args) {
        ImageResize ir = new ImageResize();
        //compress original image
        ir.compressImage("C:\\test1.jpg", "default", 200, 200);
       //create another copy of image
        ir.compressImage("C:\\test1.jpg", "d:\\abc.jpg", 200, 200);
    }
}

Arguments:
  • 1st argument - Location of your image
  • 2nd argument - If you pass "default" then it will compress the original image. If you don't want to compress original image and want another compressed image from that with other name. say c:\\test1.jpg to c:\\test2.jpg
  • 3rd/4th argument - If you don't want to change width and height then set width = 0(zero) and height = 0(zero) . It'll compress image with original width and height (Compress File size).

Download API


Get time difference in Java

When we are developing some application time is most required attribute. We have to capture when user did something and we want to show that last activity done "x seconds ago...." , "x minutes ago....","x months ago...."








Requirement : Date must be in  Nov 29, 2011 6:54:56 PM in this format. 

How to get date in this format?
        Date d = new Date();
        String current_date = d.toLocaleString();

O/P
        Nov 29, 2011 6:54:56 PM

javaQuery.core.TimeDifference

public class timed {
    public static void main(String[] args) {
        String test_date = "Nov 29, 2011 6:54:56 PM";
        TimeDifference td = new TimeDifference();
        System.out.println(td.GetDifference(test_date));
    }
}

O/P 
      1 hour ago...

URL shortening using tinyURL- An API for Java / JSP / Servlet - Unofficial API

Tiny URL Logo


Are you sick of posting URLs in emails only to have it break when sent causing the recipient to have to cut and paste it back together? API will create a tiny URL that will not break in email postings and never expires.

This is an unOfficial tinyURL Java API for link shortening.

Turn this URL:
http://www.amazon.com/Kindle-Wireless-Reading-Display-Globa lly/dp/B003FSUDM4/ref=amb_link_353259562_2?pf_rd_m=ATVPDKIK X0DER&pf_rd_s=center-10&pf_rd_r=11EYKTN682A79T370AM3&pf_rd_ t=201&pf_rd_p=1270985982&pf_rd_i=B002Y27P3M

into this TinyURL:
http://tinyurl.com/KindleWireless

Which one would you rather cut and paste into your browser? That's the power of TinyURL!

Terms of use
TinyURL was created as a free service to make posting long URLs easier, and may only be used for actual URLs. Using it for spamming or illegal purposes is forbidden and any such use will result in the TinyURL being disabled and you may be reported to all ISPs involved and to the proper governmental agencies. This service is provided without warranty of any kind.

For more information visit www.tinyurl.com
import javaQuery.j2ee.tinyURL;

public class tinyURLTest {
    public static void main(String[] args) {
        tinyURL tU = new tinyURL();
        String getLink = tU.getTinyURL("www.javaquery.com");
        System.out.println("Short Link:"+getLink);
    }
}
//output:
//Short Link:http://tinyurl.com/6kuhl6j


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.