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: https://developer.blackberry.com/java/download/eclipse/
2. Install Google maps on the simulator/device. You can go to http://www.google.com/mobile/maps/ 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:
normal #normalPlacemark highlight #highlightPlacemark #exampleStyleMap Title - My Home Location description 55.274124,25.197645 #exampleStyleMap Title - My Car Park Location description 55.279789,25.197315
String[] args = {"http://sites.google.com/site/mygooglesite/Home/location.kml"}; 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);