Friday, September 9, 2011

Java One 2011

Hello all,

On October 2–6, 2011, I'm going to be at JavaOne checking out the latest product and technology demos, meeting with fellow developers and industry experts, and learning about all things Java.

Better still, I'm going to be speaking at the event. Next is the information of my presentation:

Session ID: 24102
Session Title: Java ME and You: Discovering the Power of Mobile Masses' Inputs
Venue / Room: Parc 55 - Cyril Magnin I/II/III
Date and Time: 10/6/11, 12:30 - 13:30

"Nowadays people are connected to the network at all times via their mobile devices. This opens a huge number of possibilities for developing social network applications, because it enables you, as a developer, to create mobile applications that can deliver real-time information about anything. Imagine that your users act like sensors of a system: they send updates about the system and its behavior, and other users can benefit from it. In this session, you will discover how the users of a public transportation system in a developing country can access real-time information about the behavior of the system when this information is submitted by other users via their mobile devices with Java ME".

So I hope you can join me.

As always, JavaOne is the must-attend developer event of the year. I'm certainly going to be there, and I look forward to meeting you there, too.

High-level benefits of attending JavaOne
  • Improve your working knowledge and coding expertise
  • Choose from more than 400 sessions, including technical sessions, BOFs, keynotes, and hands-on labs
  • Learn from the world’s foremost Java experts
  • Follow in-depth technical tracks to focus on the Java technology that interests you most
  • Meet with fellow developers in formal and casual settings
  • Enjoy world-class networking and entertainment events

see ya soon!

Saturday, September 3, 2011

Google Static Maps API and JavaME

Whether you need a map for your location based application or just for fun, you can use the easiest way ever: Google Static Maps API. In this post, we are going to see how you can get a Map as an Image from a latitude and longitude point. The latitude and longitude can be obtained using Location API which we won't discuss in this post.

When writing this post, I realized there is some license restrictions in the use of Google Static Maps API in mobile Apps... I am posting it anyway just for research purposes, but I must warn you about this restriction:

Google Static Maps API Quick Review
This API lets you get an Image based on a URL and several parameters you can pass in to obtain a personalized map. You can play with the zoom, type of map, size of the image (width, height), markers at locations of the map, etc. There is a limit you have to keep in mind, the use of the API is subject to a query limit of 1000 unique (different) image requests per viewer per day, which is a lot of images... but if you need more, there is also a Premium license. For more information:

OK, what we do is the following:
  • Create a method that receives a latitude and longitude point and the size of the image as parameters.
  • Request the map image using the URL:, and adding some parameters.
  • Create an Image object and return it, so we can show it on screen.

Hands on Lab
Following is the method we were talking about. It has parameters for the latitude and longitude, and also for the width and height of the image we are requesting. The latitude and longitude can be retrieved using Location API, and the width and height can be retrieved using the Canvas class.

public Image getMap(double lat, double lon, 
                                int width, int height) 
throws IOException 
    String url = "";
    url += "?zoom=15&size=" + width + "x" + height;
    url += "&maptype=roadmap";
    url += "&markers=color:red|label:A|" + lat + "," + lon;
    url += "&sensor=true";

    HttpConnection http = (HttpConnection);
    InputStream in = null;
    byte[] imgBytes = null;
    try {
        in = http.openInputStream();

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int n = 0;
        while ((n = != -1) {
            bos.write(buffer, 0, n);
        imgBytes = bos.toByteArray();
    } finally {
        if (in != null) {
    Image img = Image.createImage(imgBytes, 0, imgBytes.length);

    return img;

As you may see, it is pretty simple to get the image of the map. The retrieving is pure HTTP request.
Next you can find an image retrieved by Google Static Maps from a location in my home town.

OK, you just saw how simply it would be if no restriction exists... What do you think about that restriction? It's kind of confusing, isn't it?

Anyway, we are going to need to find another way to show maps on our mobile apps.

see ya soon!


Google Static Maps API. [online].
Available on Internet:
[accessed on August 20 2011].

Developing Location Based Services: Introducing the Location API for J2ME. 2009. MobiForge [online].
Available on Internet:
[accessed on August 20 2011].

Mini App With Location API and Google Maps in Java ME. 2009. Nokia [online].
Available on Internet:
[accessed on September 02 2011].

Google Maps API Family. FAQ. Google [online].
Available on Internet:
[accessed on September 02 2011].