×
Namespaces

Variants
Actions
(Difference between revisions)

Reverse Geocoding an address with Nokia Maps API for JavaME

From Nokia Developer Wiki
Jump to: navigation, search
jasfox (Talk | contribs)
m (Jasfox - corrected link)
jasfox (Talk | contribs)
m (Jasfox - Link to GitHub)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Java ME]][[Category:Location]][[Category:Nokia Maps]][[Category:Code Examples]]
+
[[Category:HERE Maps for Java ME]][[Category:Code Examples]][[Category:Nokia Asha]][[Category:Nokia Asha Platform 1.0]][[Category:Series 40]][[Category:Series 40 Developer Platform 2.0]][[Category:Series 40 Developer Platform 1.1]]
 +
{{Abstract| This article explains how to use reverse geocoding service with the  [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!index.html Map API for Java ME] to get address for selected Geo location.}}
 +
{{SeeAlso|
 +
*  [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!user-guide/places/geocoding-and-reverse-geocoding.html Reverse Geocoding] (Java Developer's Library)
 +
*  [https://github.com/nokia-developer/here-maps-component-demos HERE Maps Code Examples]
 +
}}
 
{{ArticleMetaData <!-- v1.2 -->
 
{{ArticleMetaData <!-- v1.2 -->
 
|sourcecode= [[Media:Java MapRevGeoCoding.zip]]  
 
|sourcecode= [[Media:Java MapRevGeoCoding.zip]]  
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') -->
+
|devices= X3-02, Asha 311, Asha 501
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) -->
+
|sdk= [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 1.0 for Java], [http://www.developer.nokia.com/Develop/Java/ Nokia SDK 2.0 for Java], [http://www.developer.nokia.com/Develop/asha/java/ Nokia Asha SDK 1.0]
|platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later -->
+
|platform= Asha, Series 40, Symbian^1, Symbian^3
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
 
|devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) -->
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
+
|dependencies=HERE Maps API for Java ME v1.3
 
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|keywords= Nokia Maps, Java ME, search, reverse geocoding
+
|keywords= HERE Maps, Java ME, search, reverse geocoding
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
Line 23: Line 28:
 
}}
 
}}
  
{{Abstract| This article explains how to use reverse geocoding service with the  [http://developer.here.net/java Map API for Java ME] to get address for selected Geo location.}}
 
  
 
{{SeeAlso|
 
*  [http://developer.here.net/java Map API for Java ME]
 
* [http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/Code_examples/#search Search Demo]
 
}}
 
  
 
== Introduction ==
 
== Introduction ==
Line 35: Line 34:
 
[[File: MapRevGeoCode.png]]
 
[[File: MapRevGeoCode.png]]
  
The [[http://www.developer.nokia.com/Develop/Maps/Maps_API_for_Java_ME/ Maps API for Java ME] facilitates the easy embedding of the Nokia 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.
+
The [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!index.html 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 ==
 
== SearchFactory and ReverseGeocodeRequestListener ==
Line 104: Line 103:
 
== Summary ==
 
== Summary ==
  
The  [http://developer.here.net/java Map API for Java ME] offers rich functionalities that allows to integrate all the main Nokia Maps features in a Java ME application, with just a few lines of code.
+
The  [http://www.developer.nokia.com/Resources/Library/HERE_Maps_Java_ME/#!index.html 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.

Latest revision as of 09:44, 20 September 2013

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
Compatibility
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
Article
Keywords: HERE Maps, Java ME, search, reverse geocoding
Created: symbianyucca (27 Feb 2012)
Last edited: jasfox (20 Sep 2013)


Contents

[edit] Introduction

MapRevGeoCode.png

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.

[edit] SearchFactory and ReverseGeocodeRequestListener

The SearchFactory class (available in the 'com.nokia.maps.search ' 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.

[edit] 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) {
...
}
}

[edit] 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();
revG.reverseGeocode(mapCanvas.getMapDisplay().getCenter(),this);

[edit] 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());
display.setCurrent(alertView);
}


[edit] Resources

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

[edit] Summary

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.

This page was last modified on 20 September 2013, at 09:44.
143 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×