Updates from May, 2008 Toggle Comment Threads | Keyboard Shortcuts

  • pit 9:17 am on May 14, 2008 Permalink | Reply
    Tags: , , , , map images   

    How to use Google Maps data within your mobile application 

    Note: You can find this article also on Forum Nokia Wiki: How to use Google Maps data in mobile applications

    Today we’ll see how to use Google Maps data within a mobile application.
    Google Maps offers REST services that allows accessing its data with simple HTTP requests, so we can easily integrate them within our mobile apps.

    Signup for a Google Maps API key

    First thing you must do is to signup on this page:
    Once done, you’ll get a key (a simple String) you’ll use for all your query to Google Maps services

    Static maps

    Standard Google Maps code is suited for web applications, since it includes alot of Ajax functionalities, that are not really useful if you’re building a mobile application. So, the solution is to use static maps service, that will allow us to retrieve single images, easily usable within our apps.

    Static maps service supports different image formats (png32, gif, jpg) and customizable image size, so that we can get perfect images for all our needs. As an example, suppose we want to retrieve the location at:

    • latitude: 41.867878
    • longitude: 12.471516

    We can simply retrieve this URL with an HTTP GET request:


    This way, we’ll get a PNG32 image, with a width of 240 pixels, and a height of 320, centered at point (41.867878,12.471516), and with a zoom level of 8 (zoom can go from 0 to a maximum level of 19).

    Google Maps static image sample

    Geocode an address

    From Google Maps docs:
    Geocoding is the process of converting addresses (like “1600 Amphitheatre Parkway, Mountain View, CA”) into geographic coordinates (like latitude 37.423021 and longitude -122.083739)

    So, let’s assume we want to build an application that displays the address typed by our user. We should firstly geocode its address to geographics coordinates.
    To do this, Google Maps offer another REST service easily accessible with simple HTTP requests.

    Let’s say you want to geocode this address “Leicester Square, London”, then you’ll request this URL:


    and you’ll get this output:



    • the first number is a code, that in this case (200) means that geocoding has been successfull (for a full list of status codes you can see here: [1])
    • the second number gives a measure of geocoding accuracy (from 0 to 9 – maximum accuracy)
    • 3rd and 4th numbers represent latitude and longitude of the geocoded address, so these are the coordinate we’ll use to retrieve the map through the static map service we’ve seen before

    As you can see, there is an ‘output’ parameter within the geocode request, and this means that we can choose the output format we prefer for our needs. Supported formats are:

    • xml
    • kml (same as xml, but with different Content-Type)
    • json (not really useful for mobile apps)
    • csv (comma separated values)

    Proxy server, usage limits

    Since your Google Maps API key is bound to a specific URL, to access map services you should setup a proxy server that will receive HTTP requests from your mobile application and forward them to Google Maps REST URLs, giving back Google responses to mobile clients.

    Also, be aware that there is a limit to the number of requests (both for static maps and geocode service) you can do each day. For personal uses they’re more than enough, anyway consider this point if you plan to develop commercial services.

    Google Maps J2ME API and sample application

    Now, you want code right? :) Here it is:

    Google Maps sample application screenshot

    • Francesco 4:37 pm on May 22, 2008 Permalink

      I’m trying to execute the code you posted on the Forum Nokia Wiki. I use the Sun Wireless Toolkit and the EsclipseME IDE.
      I get the following exception when invoking the retrieveStaticImage method:

      at javax.microedition.lcdui.ImmutableImage.(+11)
      at javax.microedition.lcdui.Image.createImage(+40)
      at GoogleMaps.retrieveStaticImage(+28)

      could you help me?

      thanks a lot,

    • pit 4:43 pm on May 22, 2008 Permalink

      Hi Francesco,

      this has probably something to do with illegal/corrupt data coming from server. If you try getting the map URL directly in your browser, does it work?

      Also, which format are you using for your static maps?


    • Francesco 12:06 pm on May 23, 2008 Permalink

      Hi Pit,
      thanks for your fast answer. I tried to change the format for the static map to png16 (I was using png32) and it works :D

      Now I have a problem with displaying the image: I can see just the first few pixels while the rest of the screen is black (width is alright, while the problem is with the height)

      My code is pretty simple:

      Image map = gMap.retrieveStaticImage(320, 240, lanLng[0], lanLng[1], 15, “png16″);
      Form f = new Form(“Image”);

      It is my first approach to midlets and I don’t really know what’s wrong. I also trying using canvas but I get the same result. Do you have any suggestion?

      thanks again,

    • pit 10:58 am on June 9, 2008 Permalink

      Hi Francesco,

      sorry for the delay of my answer, but I totally missed your reply… :-/

      Anyway, do you have this problem on emulators, or on real devices?


    • Olaseni 8:39 am on June 22, 2008 Permalink

      Please I need help in finding a source code for designing a map on mobile application, I intend using a scanned image for the map.

    • Paul 6:32 am on November 24, 2008 Permalink


      I’ve run into the same problem as Francesco. Only the first 50 or so pixels of the image from the top going down loads. This is in the emulator. Any thoughts on what may be happening would be much appreciated.

      Thanks for the great guide.

    • IKP Lab 1:32 pm on January 21, 2009 Permalink

      Try to use DataInputStream() and readFully(). That solved my problems which were the same like yours – approximately 50pix of the image were displayed on the screen. Hope it helps. ;)

    • ravi 7:25 am on February 12, 2009 Permalink

      i want to geocode in my midlet application can any one help me

    • Guzzler 1:24 am on February 17, 2009 Permalink

      Can you explain more the DataInputStream() and readFully() version?
      I replaced the InputStream() with DataInputStream() instead. I don’t understand how to use the readFully().Can you post the altered code like the examples above?
      I have the same problem with the black piece of the image. Thanks in advance.

    • Guzzler 1:36 am on February 17, 2009 Permalink

      Nevermind. My mistake. Found it. Thanks a lot guys! ;-)

    • Ernesto 7:09 am on May 12, 2009 Permalink

      Hello guys!!

      Guzzler, can you tell us what was your problem, please??? Im gettin a NullPointerException. I changed as Francesco said to png16 but it doesn’t work for me. As the matter of fact I can get the image by the URL in the browser, but not in code.

      Please can anybody help me out???

    • Preethi 5:42 pm on August 20, 2009 Permalink

      Hi Ernesto,

      Did you find a solution to your problem even i get the same exception …
      startApp threw an Exception

      Please help me to solve this problem…

    • vfede 4:59 pm on September 24, 2009 Permalink

      Ciao jappit,
      sto usando la tua ottima classe “GoogleMaps” del forum nokia per delle prove con J2ME, funziona tutto ma solo se tolgo tutte le var double e le sostituisco con int, altrimenti mi da un “Error preverifying class GoogleMaps”. sai indirizzarmi verso la soluzione del problema? come faccio riconoscere i double a J2ME? te ne sarei molto grato, grazie ^_^

    • Nilesh 1:02 pm on October 8, 2009 Permalink

      Hello All;
      I am Developing an Application to get current location on googleMap for that i got Api Key.
      I am developing this application on wtk & eclipse Ganymede. I am getting Exception
      at AT.RetrieveLocation.checkLocation(+288)
      at AT.RetrieveLocation.run(+12)
      thanks in Advance

  • pit 4:59 pm on May 12, 2008 Permalink | Reply
    Tags: file upload, , http, , multipart request, post, , upload image   

    HttpMultipartRequest: simple file uploads with J2ME 

    Today’s code is related to file uploads using J2ME. We’ll use Http POST MultiPart requests to handle and transfer data from J2ME application to server; since there is no builtin support for MultiPart, we’ll have to build the request body by hand.

    j2me file upload sample screenshot

    Code is limited to 1 class only (HttpMultipartRequest), that will be easy to include and easy in your code, just instatiate it with its constructor:

    HttpMultipartRequest(String url, Hashtable params,
    String fileField, String fileName,
    String fileType, byte[] fileBytes)

    and then send data to server (and get response) with its send() method. As you can see from the constructor, this implementation support also parameter passing, that will be posted to server together with the file bytes.

    Detailed and explained code (with sample client and server code) is available here: HTTP Post multipart file upload with J2ME Wiki article. To directly download source code, click here.

    • Girish 10:07 am on February 11, 2009 Permalink

      Hi! I have tried using the class in a MIDlet, but I cannot make it work. Can you help me? I’ve posted that on a forum, but I haven’t found any help yet.

    • Kapil Katiyar 9:45 am on September 15, 2011 Permalink


    • sabri 9:29 pm on November 30, 2012 Permalink

      hi …
      thanx for ur help … the code working success full except the picture cann’t shown after saved on server because viewer can’t open this picture because the fi;e appears to be damaged …
      and the size on server is larger than the size on mobile …
      please help me to solve this problem ….

  • pit 1:28 pm on May 9, 2008 Permalink | Reply
    Tags: , , , parser, rss,   

    Parsing RSS feeds with J2ME and KXML 

    Some days have passed since last J2ME tutorial, so here is a fresh new one!

    Today we’ll see how parsing a RSS feed with J2me is easy using KXML library, a fast and small XML pull parser, expecially suited for constrained environments like mobile devices. A live sample, parsing the RSS feed of this blog, is available here.

    J2ME Kxml rss parser screenshot

    The detailed explanation of source code is available on my Forum Nokia Wiki article: J2ME RSS Parser with KXml. If you’re interested only in plain source code, you can pick it up here (it includes also the sample midlet you find on the emulator page). To use KXmlRssParser class, you must simply do:

    KXmlRssParser parser = new KXmlRssParser();
    Vector rssItems = parser.parse(yourFeedURL);

    and the parse() method will return the complete list of parsed Items, as instances of RssItem class. Source code is of course simplified, for the purpose of this tutorial, as it only considers title, link and description tags of each <item>, but once you understand KXml logic you can extend it, without much effort, to include other infos from RSS feed.

    Other resources you might find useful:

    • Mahesh 2:31 pm on June 19, 2008 Permalink

      Hi i m a trainer in my comp, i saw the code its very nice n the standards are maintained i this coding. Currently i m working on xml parsing, so i juz want to know that if i want to display the names(channel names) in a list view on device, then is this the same procedure i need to follow or else there is a diferent way. If so can u plz tell me?

    • Pit 12:23 pm on June 20, 2008 Permalink

      Hi Mahesh,

      the approach and code described in this post works only to parse (and display) RSS feed items, but you can easily adapt it to parse channel names, or any other infos contained within the RSS feed.


    • ram 8:09 am on July 8, 2010 Permalink

      I m working on a J2me Project.I ve succesfully implemented Client Login system and am able to get the RSS feed of ContactsI used ur example to parse the RSS feed..

      I want to fetch all the contact names/email ids/photo and display them on screen.

      From the Rss Feed I was able to parse out “contact name”

      The problem is in parsing image and especially email address..
      The Rss feed lines goes something like

      I want to parse out the address from the above line for all contacts.By the way I use KXML library for parsing in j2me..
      Kindly help Plz!

    • Ratnesh 6:12 am on August 29, 2011 Permalink

      Well i am trying to make this but i having one problem . when i am declaring object f KXmlPArser() its showning me error..

      KXmlParser parser = new KXmlParser() ;

      at this particlauar line i am gettign the error.

      i am usingn Eclipse ME
      KXml 2.3

      i urgently need help on this .. I had added classpath also.

  • pit 6:18 pm on May 8, 2008 Permalink | Reply
    Tags: , , , puzzle   

    First iPhone game: AnimaLogic is back! 

    Since iPhone’s arrive in Italy seems to be near, here’s a first port of AnimaLogic, one of the first web runtime games!

    Iphone Animalogic puzzle game screenshot

    You can try a first (very beta, as always :)) version here.

    iPhone animalogic game qrcode

  • pit 3:02 pm on May 5, 2008 Permalink | Reply
    Tags: darts, , ,   

    J2ME game code: let’s play Darts! 

    Darts is an ideal game for mobile users, since it does only require few seconds for a match, and could be really helpful while waiting for a bus.. (If you must wait a bus in Rome, it’s easy you’ll become a Darts champion within a day :))

    J2ME game darts screenshot

    This simple game was originally included, as easter egg, in the midlet built for 2007 Edition of Rome JavaDay, to help folks being awake during long talks :) For a live test you can go directly to the emulator page.

    2007 Rome JavaDay Midlet screenshot

    Now, It’s source code is fully available to everyone to (ab)use, and please be kind with me for the total lack of comments…

    Here is the source code, and the full sample midlet if you want to try it out on your phone.

    • sejal 3:55 pm on April 5, 2011 Permalink

      hey…when i execute this code on wtk..its showing me errors saying dat

      package com.jappit.japdarts.app does not exist
      import com.jappit.japdarts.app.JapDarts;
      package com.jappit.japdarts.utils does not exist
      import com.jappit.japdarts.utils.ScoreManager;
      can u plz help me with this..where do i get the functions and variables in the package package com.jappit.japdarts.display; from ?…pls reply asap !!

    • Renniel 4:09 pm on October 8, 2011 Permalink

      where is the code sir?? thnaks

compose new post
next post/next comment
previous post/previous comment
show/hide comments
go to top
go to login
show/hide help
shift + esc