Go to Content


Home > Library

How to convert geographic coordinates to addresses and vice versa

By bada Master | 2149 views | Sep 13, 2010

You would have come across many situations where you wanted to find the geographic coordinates corresponding to an address (Geocoding) or address corresponding to a particular coordinate (Reverse – Geocoding). This can be performed in bada with a few lines of code.

As in any other location service, geocoding also requires support from a location service provider. In this discussion, we will use deCarta® (http://www.decarta.com/) as the location service provider. To use this service provider, it is required to get a client name and password from the deCarta developer zone (http://developer.decarta.com/). All deCarta services are handled on deCarta servers and delivered to the mobile device over the network.

Let us discuss about the geocoding and reverse-geocoding services of bada in detail.

Common steps in geocoding and reverse-geocoding

For both geocoding and reverse-geocoding, there are some common steps to be followed. They are,

  • 1. Connect to the service provider.
  • 2. Set the preferences if required. It’s up to the user whether to use preference in the service request or not.
  • 3. All the APIs for both geocode and reverse-geocode are asynchronous. You should implement the IGeocodingServiceListener to receive the results.

The below code snippet shows how to connect to the server and set the preference values.

String extraInfo ("ClientName=guest;ClientPassword=1234;HostUrl=
CountryCode countryCode = COUNTRY_US;

IGeocodingServiceProvider* pProvider = 
	("deCarta", LOC_SVC_PROVIDER_TYPE_GEOCODING, extraInfo));

GeocodingServicePreferences* pPreferences = 
	static_cast <GeocodingServicePreferences*>

result r = pPreferences->SetBaseCountryCode(&countryCode);

In the above example, extraInfo is the additional information (e.g. username-password) required by the location service provider to serve the service request. . The extraInfo provided here is just a dummy sample. Users need to get their values from deCarta®. For deCarta®, it is required to set the country code to get the geocode information.
Now, let us see how we can use geocoding and reverse-geocoding services from the connected service provider.

Steps specific to Geocoding Service

With the connected geocoding provider, you can query the coordinates corresponding to a given address. This is possible by giving address in two ways,

  • Provide the address in string format.
  • Provide the address as ‘addressInfo’ structure.

Sample for address in string format

result r =  pProvider->Geocode(String("4 N 2ND ST, San Jose CA 95113"), null,  pPreferences
, *pListener,  requestId);

Sample for address as ‘addressInfo’ structure.

result r = addressInfo.SetField(ADDRESS_FIELD_CITY, "San Jose");
r = addressInfo.SetField (ADDRESS_FIELD_STREET_NAME, "N 2ND ST");

r = pProvider->Geocode(addressInfo, null, pPreferences, *pListener, requestId);

The resulting information can be received in IGeocodingServiceListener::OnGeocodingRequestResultReceivedN ().

Below given is the sample implementation for OnGeocodingRequestResultReceivedN() method.

Landmark* pLandmark = dynamic_cast<Landmark*>(pLandmarks->GetAt(0));

const QualifiedCoordinates* pCoord = pLandmark->GetQualifiedCoordinates();

Steps specific to Reverse- Geocoding Service

You can use the connected provider, to query the address of given coordinates also.
Below given sample shows how to do it.

result r = pProvider->ReverseGeocode(coordinates, null, *pListener, requestId);

The result will be received in IGeocodingServiceListener::OnReverseGeocodingRequestResultReceivedN()

Below given is the sample implementation for OnReverseGeocodingRequestResultReceivedN() method.

Landmark* pLandmark = dynamic_cast<Landmark*>(pLandmarks->GetAt(0));

const AddressInfo* pAddress = pLandmark->GetAddressInfo();

Geocoding in bada Help Contents

Bada provides comprehensive help on this topic. Here are some pointers to it.

bada Developer Guide > bada Open APIs > Using the bada Open APIs > Location > Locations Services > Use Cases and Examples > Handling Geocoding

bada Developer Guide > bada Open APIs > Using the bada Open APIs > Location > Locations Services > Use Cases and Examples > Handling Reverse Geocoding

bada API Reference > Namespace List > Osp::Locations > Osp::Locations::Services

Did this document help you? Yes | It's good,but ... | Not Helpful