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 03:48, 25 June 2013 by hamishwillee (Talk | contribs)

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 the Map API for Java ME to get address for selected Geo location.

See Also

Article Metadata
Code ExampleTested with
Devices(s): X3-02, Asha 311, Asha 501
Platform(s): Asha, Series 40, Symbian^1, Symbian^3
Nokia Asha
Nokia Asha Platform 1.0
Series 40
Series 40 DP 2.0
Series 40 DP 1.1
Dependencies: HERE Maps API for Java ME v1.3
Keywords: HERE Maps, Java ME, search, reverse geocoding
Created: symbianyucca (27 Feb 2012)
Last edited: hamishwillee (25 Jun 2013)




The HERE Maps API for Java ME facilitates the easy embedding of the HERE Maps service into Java ME applications. The API includes reverse geocode functionality, which makes it possible to find the address of the given geographical coordinates.

SearchFactory and ReverseGeocodeRequestListener

The SearchFactory class (available in the ' ' package) offers various functionalities, including geocode, reverse geocode, and search. These operations are performed in an asynchronous manner, for each service there is a listener interface defined for result callback, which is used when the service is used in asynchronous manner. This interface implements methods for informing of the successful completion of the request as well as there is separate method to be called in error situations.

Implementing reverse geo coding midlet

To be able to utilizing the reverse geo service, there need to be class which is implementing the required PlaceSearchRequestListener interface, this interface defines following 2 methods:

  • onRequestComplete(ReverseGeocodeRequest request, Location[] result)
  • onRequestError(ReverseGeocodeRequest request, java.lang.Throwable error)

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 ReverseGeocodeRequestListener, ...
public void onRequestComplete(ReverseGeocodeRequest request, Location[] result){
public void onRequestError(ReverseGeocodeRequest request, java.lang.Throwable error) {

Starting the query

Before the service can be used you need to get the instance of search factory, which implements the service, this is handled by simply calling the getInstance method from SearchFactory:

sm = SearchFactory.getInstance();

Then you need to create the ReverseGeocodeRequest instance. This is handled by calling createReverseGeocodeRequest method for the search factory, which after you can use the methods implemented in the reverse geo coding request to handle the actual reverse geo coding request. Note that this request class is implementing multiple functions for making the request, and if you choose you can use the synchronous versions, which would allow you to handle the reply right after the function cal. With this example we are using asynchronous methods, and as we implemented the ReverseGeocodeRequestListener interface we can use the this with with the method call, the other argument used with this method call, is geo the location to be used with reverse geo coding, in this example the center of the map is used as the geo location for the service.

ReverseGeocodeRequest revG = sm.createReverseGeocodeRequest();

Handling the result

Successful completion of the asynchronous reverse geo coding will be notified by calling the onRequestComplete method implemented for the ReverseGeocodeRequestListener interface. The onRequestComplete will be called with ReverseGeocodeRequest argument, as well as Location array holding the results for the request.

public void onRequestComplete(ReverseGeocodeRequest request, Location[] result){
if(result.length > 0){
Location firstLocation = result[0];
Address address = firstLocation.getAddress();

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

public void onRequestError(ReverseGeocodeRequest request, java.lang.Throwable error){
Alert alertView = new Alert("Search request error: " + error.getMessage());


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


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

116 page views in the last 30 days.