Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 09:40, 27 February 2012 by symbianyucca (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Reverse Geocoding an address with Nokia Maps API for JavaME

From Wiki
Jump to: navigation, search

This article explains how to use reverse geocoding service with Maps API for Java ME API to get address for selected Geo location.




The [Maps API for Java ME allows to easily embed Nokia Maps service into Java ME applications. The API includes reverse geocode functionality, which allows retrieving address of the given geographical coordinates.

SearchManager and SearchListener

The SearchManager class (available in the package) offers various functionalities, including geocode, reverse geocode, and search. These operations are performed in an asynchronous manner, and a SearchListener is notified when they are completed, cleared or when an error has occurred.

Implementing reverse geo coding midlet

To be able to utilizing the reverse geo service, there need to be class which is implementing the required SearchListener interface, this interface defines 3 methods which are:

  • searchRequestError(SearchManager source, java.lang.Throwable error)
  • searchRequestFinished(SearchManager source)
  • searchResponseCleared(SearchManager source)

And to include this interface in your midlet implementation you need to use the implements clause to, basic code that handles this is shown below:

public class MapRevGeoCoding extends MIDlet 
implements CommandListener, SearchListener
public void searchRequestFinished(SearchManager searchManager){
public void searchRequestError(SearchManager searchManager, Throwable error) {
public void searchResponseCleared(SearchManager searchManager) {

Starting the query

Before the service can be used you need to get the search manager instance, which is implementing the service, this is handled simply calling the getInstance method from SearchManager:

sm = SearchManager.getInstance();

Then you need to set the SearchListener for the SearchManager, so you would be able to get the results for queries. With this example the class in which the service is used implements also the interface, so you can use this reference as SearchListener. Before attempting to start the query it is advisable to clear the previous query, which is handled by called clear for the SearchManager instance. Then the actual reverse geo service query can be started by calling reverseGeocode. This method takes one argument which is geo location, in this example the center of the map is used as the geo location for the service.


Handling the result

Successful completion of the reverse geo coding will be notified by calling the searchRequestFinished method implemented for the SearchListener interface. The searchRequestFinished will be called with SearchManager argument, which can be used for retrieving the actual result data by simply calling getLocations method. The getLocations method returns array of Location objects, so you should check whether there is multiple possible results for the query, with this example only the first match is used.

public void searchRequestFinished(SearchManager searchManager){
if(searchManager.getLocations().length > 0){
Location firstLocation = searchManager.getLocations()[0];
Address address = firstLocation.getAddress();

The query could also be finished with error, and to handle those you should also implement the searchRequestError method, in this example this method simply informs the user of the possible problem.

public void searchRequestError (SearchManager searchManager, Throwable error) {
Alert alertView = new Alert("Search request error: " + error.getMessage());


Full source code of the MapRevGeoCoding is available here: File:Java


The Java ME Location API offers rich functionalities that allows to integrate all the main Ovi Maps features in a Java ME application, with just a few lines of code.

98 page views in the last 30 days.