Thursday, 16 May 2013

Google maps on BlackBerry: Add location markers using KML

Google maps for Blackberry 

Today we will be starting with a BlackBerry application that invokes the google map with our given latitude/longitude location sets. We will learn how to make our application more appealing with the 'google' effect ;)

Right, so you're actually bored with the native BlackBerry maps application that comes with the BlackBerry device?

No? Really?You can't say that!

Well I too was a bit uncomfortable developing maps applications using the native BlackBerry maps. To be honest it  never gave me the correct direction from one place to another and so I decided to go with the Google maps that not only has an enhanced UI experience but is quite accurate too.

So first thing first. What do we need?

1. An eclipse IDE that comes bundled with BlackBerry JDE these days. Get that bundle here:

2. Install Google maps on the simulator/device. You can go to from BlackBerry browser and install the Google maps application from there.

3. A public url (You can't upload your .kml file to your local server like tomcat) to upload the KML file to be used in our application. (The url must not be 'https', otherwise we are going to get an error: "The community map could not be displayed because it contains errors"). I prefer using google sites for uploading my kml files.

Next, it's time to start coding our application. Here we go! 

First we need to know if Google map is installed on the mobile phone. We do this by passing as string the module name to the code module manager.

int mh = CodeModuleManager.getModuleHandle("GoogleMaps");

If the value of mh is 0 it means Google map is not installed. 

Now , we will create our KML file by clicking in Eclipse's File menu then creating a file with the extention .kml. The file contains our locations to be marked on the map. 

The KML file's full path should be provided to the Application Descriptor. Again the file should not be uploaded on our internal server and the url must not be https.

The KML file looks like this:

   Title - My Home
   Location description
   Title - My Car Park
   Location description

The normal placemark and highlighted placemark can be used to change marker colour or icon and add styles for markers when highlighted (by rolling over icon) or in normal state. The markers are invoked inside the placemark tag of the location. 
String[] args = {""}; 
  ApplicationDescriptor ad = CodeModuleManager.getApplicationDescriptors(mh)[0]; 
 ApplicationDescriptor appdes = new ApplicationDescriptor(ad, args);
That's it, its time to invoke the google maps application and voila!
ApplicationManager.getApplicationManager().runApplication(appdes, true);
Let's see the screenshots of the above code result:


Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Hosting