Displaying a Map in a bada application
We continue our exploration into the bada API. Today we have a simple bada tutorial to display a map control on a form. Unfortunately, as of today, there is no map control available in the GUI editor, therefore you have to create one within your code. You may want to take a look into this simple UI bada app first, it might make things easier to understand.
First of all you will need to get a developer account at deCarta, as it is the maps service provider that we are going to use. They do take up to a few hours to send you the login information, so you may want to do that right away.
By the way, later on you will be able to define and download the app’s manifest directly through the official site, for not we have to edit them ourselves. An app dealing with maps needs a special privilege. Open the manifest.xml with a text editor and modify the relevant part as follows:
<Privileges> <Privilege><Name>MAP_SERVICE</Name></Privilege> </Privileges>
I have created an empty form (as described in another bada tutorial) for this one and linked FLocations and FLocationControls libraries in the project settings as descibed on our bada forums. Then, you need to add a few declarations to your app’s header (assuming you used the wizard to create a bare-bone bada project).
1. Namespaces and Headers for the Location features
#include <FApp.h> #include <FBase.h> #include <FLocations.h> #include <FGraphics.h> #include <FIo.h> #include <FLocales.h> #include <FText.h> #include <FSystem.h> #include <FUi.h> using namespace Osp::App; using namespace Osp::Base; using namespace Osp::Base::Collection; using namespace Osp::Locations; using namespace Osp::Locations::Controls; using namespace Osp::Locations::Services; using namespace Osp::Graphics; using namespace Osp::Io; using namespace Osp::Locales; using namespace Osp::System; using namespace Osp::Text; using namespace Osp::Ui; using namespace Osp::Ui::Controls;
2. Add two private variables to the app’s class for a frame and a form
class SimpleLocation :
public Application
{
private:
Frame *pFrame;
Form *pForm;
3.Finally change the OnForeground function of the app to create and display the map. This is surely not the best way (it’s better to put most of this code in app’s initialization function), nevertheless this will do for a simple demo.
void
SimpleLocation::OnForeground(void)
{
result r;
String providerName = L"deCarta";
String extraInfo = L"ClientName=your-log-in;ClientPassword=your-password;HostUrl=http://ws.decarta.com/openls/openls";
int width = 0;
int height = 0;
Coordinates center = Coordinates();
center.Set(37.786505, -122.39862, 0);
Map * pMap = null;
pFrame = this->GetAppFrame()->GetFrame();
pForm = new Form();
pForm->Construct("IDF_FORM1");
pFrame->AddControl(*pForm);
pFrame->SetCurrentForm(*pForm);
// we will use all available space of the form for our map control
width=pForm->GetCanvasN()->GetBounds().width;
height=pForm->GetCanvasN()->GetBounds().height;
// Connect to map service provider
IMapServiceProvider* pProvider =
static_cast<IMapServiceProvider*>(ProviderManager::ConnectToServiceProviderN
(providerName, LOC_SVC_PROVIDER_TYPE_MAP, extraInfo));
if (null == pProvider) goto CATCH;
// Create map
pMap = new Map();
if (null == pMap) goto CATCH;
// Specify map's size (all space available on the form)
r = pMap->Construct(Osp::Graphics::Rectangle(0, 0, width, height), *pProvider);
if (IsFailed(r)) goto CATCH;
// Set desired zoom level (high, street)
r = pMap->SetZoomLevel(17, false);
if (IsFailed(r)) goto CATCH;
// Set center position to display
r = pMap->SetCenter(center, false);
if (IsFailed(r)) goto CATCH;
// Enable my location
pMap->SetMyLocationEnabled(true);
// Render a map (add it to the form first)
pForm->AddControl(*pMap);
r = pMap->Draw();
if (IsFailed(r)) goto CATCH;
pFrame->Draw();
pFrame->Show();
return;
CATCH:
delete pMap;
delete pProvider;
}
Keep in mind that you need to input your own login details for deCarta into the connection string. Build, run and you shall see something like this:
Related posts:
the Flagship blog & community for App Developers with main focus on Samsung's bada and cross-platform technologies 





11 Responses to “Displaying a Map in a bada application”
By Bada-beginner on May 26, 2010 | Reply
hi
am new to Bada
tried to create a simple app with the help of this sample
build the project successfully with out any error but after “initializing system 100%” its strucked at “Launching CustomListS…ebug (78%)” – until i close the simulator (waited even for more that 30-40 min to complete)
By Technoboy on Aug 6, 2010 | Reply
Hello~
I followed the steps and was faced with the following error message;
Installation failed
ErrorCode : 0115.
I did the privilege, account from DeCarta things!
Help..
Thanks in advance.
By neeraj on Aug 8, 2010 | Reply
send ur code….
By odev on Aug 12, 2010 | Reply
Hi,
I have question regarding deCarta… If i use the developer account while developing the app, what account will be used when i distribute the app at samsung appstore?
Thanks
By Peter on Aug 18, 2010 | Reply
hello badadevs!
i have the same problem re. “Installation failed ErrorCode : 0115.”
i have set the MAP_SERVICE privilege in the manifest.
i have tried to download the manifest from the developer.bada.com site, but i was not albe to find the MAP_SERVICE privilege
thank you!
peter
By wit on Aug 19, 2010 | Reply
Hmmm strange… I will look around.
By Kamen on Aug 24, 2010 | Reply
Aren’t we supposed to delete the canvas object from GetCanvasN ?
By Hannes on Aug 24, 2010 | Reply
theres no MAP_SERVICE privilege, only LOCATION_SERVICE.
By cjw on Sep 1, 2010 | Reply
Do you know how create route from current location in bada?
By Franz on Dec 18, 2010 | Reply
Found a solution to the 0115 error if someone’s intrested.
Looking at the sdk MapViewer sample I saw these privileges in the manifest:
IMAGE
LANDMARK
LOCATION_SERVICE
MAP_SERVICE is not specifies and it doesn’t seem to exist..
With these privileges my app is working.