Blackberry: Passing KML file to Google Maps
I want to know that can I pass KML as a string to google map application?
Code snippet:
//KML String
String document = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><Folder><name>Paths</name><open>0</open><Placemark><LineString><tessellate>1</tessellate><coordinates> -112.0814237830345,36.10677870477137,0 -112.0870267752693,36.0905099328766,0</coordinates></LineString></Placemark></Folder></Document></kml>";
//Invoke Google Maps
int module = CodeModuleManager.getModuleHandle("GoogleMaps");
if (module == 0) {
try {
throw new ApplicationManagerException("GoogleMaps isn't installed");
} catch (ApplicationManagerException e) {
System.out.println(e.getMessage());
}
}
String[] args = {document}; //Is this possible???
ApplicationDescriptor descriptor = CodeModuleManager.getApplicationDescriptors(module)[0];
ApplicationDescriptor ad2 = new ApplicationDescriptor(descriptor, args);
try {
ApplicationManager.getApplicationManager().runApplication(ad2, true);
} catch (ApplicationManagerException开发者_StackOverflow e) {
System.out.println(e.getMessage());
}
After much R&D...the answer that I found out was that - No, we cannot pass KML as string.
Google Maps Mobile accepts a URL parameter. This needs to be in the form of "http://" and could be either specific parameters (such as "http://gmm/x?....") or a KML file ("http://..../sample.kml").
You MUST parse your mapFile (KML, gpx, txt) IF using the GoogleMaps API.
if all you want is to see your KML file inside a googlemaps window, you can goto the standard http://www.googlemaps.com and inside the ADDRESS box, you put the complete http address of your kml file.
until april2012 this used to work perfectly and the sidebar would be populated correctly, with clickable items (clicking on sidebar entry [e.g. "point 1" would fly-to the equivalent location). as of may2012, this feature is working incorrectly.
IF you want to take things one step further, you can have a PHP page echo the kml (on the fly KML rendering from database or file). BUT, googlemaps will not refresh your dynamically generated output for 10 to 15 minutes.
PM me if you want some javascript GPX and TXT mapFile rendering for GoogleMaps API vs3
精彩评论