Create Google Map QR Code in Java iText

For some posts now, we have been discussing QR codes in length by providing relevant PDF, PNG and HTTP Servlet based examples. We saw how to create calendar and contact based QR code events with working examples.

In this tutorial,  we will discuss how to create the following event based QR codes in Java:
  • Email Address
  • Geo Location
  • Phone Number
  • SMS
  • Text
  • URL
  • WiFi Network
The code to generate each of these event based items is the same as given in our earlier examples. However, you need to modify the input string to support the values we will have to supply for these codes. So, I would strongly urge the readers to grab the working code from our earlier tutorials and so a simple replace to support these codes. The portion of code that needs to be changed to support the generation of these QR codes is documented below:

Email Address
It is easy to create a QR code for this and it falls on the same lines of the contact QR code. The change you need to make to the code is provided below:

6 String contact_email="";//mailto is the prefix for email
The keyword you need to supply for this QR code is "mailto:". The HTTP servlet code can be done over a HTML form with only one field in it.

Geo Location
Often, you would want to specify your business address over a map with a search query(optional). In order to create a location based QR code, you need the latitude, longitude and Query string. A Java code snippet change that you need to make to support this code is captured below with comments:
6 String map_based_qr_code="geo:45,45?q=test";//geo: is the keyword
7 //first 45 is latitude, second 45 is longitude, add "?q=" and include query string
This code requires you have three form fields, if you are trying a HTTP servlet based example. A QR code reader would automatically recognize that this is a map based one and would take map based action on your mobile.

Phone Number
For a phone number based QR code, you need to add the prefix "tel:" before the number. You can follow the same instructions as given earlier for Email address.

For SMS based QR code, add "smsto:" prefix followed by the number to which you want to send the text message. Then put a ":" terminator to the number and add the SMS text, all in one string.

URL and Text based QR codes are flat and easy. Just add a http prefix for URL and the plain text string for the text based one.

WiFi Network
If you want to give free (?) wireless access point information over a QR code, you need to make sure you supply the following information to the QR code generator:

  • SSID
  • Password
  • Network Type: (can be WEP, WPA/WPA2 or "No encryption") 

A sample Java string you need to construct is shown below


WIFI is the keyword. S denotes SSID, T denotes the encryption type (WEP, WPA or nopass), P denotes the password you need to use.

I will provide the QR Droid based screenshot in each of these cases in a later tutorial. But, generation of this is easy and you have to follow the code we have written in earlier tutorials and just replace the code where required.

If you are stuck or have a comment to improve this article, post it in the comments section.

No comments:

Post a Comment