In a previous post I mentioned that I would be doing some experimenting with the
JAK - Java API for KML. I have now created a simple program that creates a KML file using co-ordinates obtained from calling the
Google Geocoder.
If you wish to review the whole program I have made it available
here (4mb).
The main parts of the code are as follows:
GeoCoder class
- converts a street address into a longitude/latitude point.
- call getLocation method with a string representing the address.
- class uses Google Geocoder.
Refer to the Geocoder.java class file in the download for more information on how this works.
Main Class
- assigns an address from the first command line argument
- calls the GeoCoder.getLocation method with Address String
1 | location = Geocoder.getLocation(address).toString(); |
- creates a KML file using the location value returned by the GeoCoder class
01 | final Kml kml = new Kml(); |
02 | kml.createAndSetPlacemark() |
04 | .withOpen(Boolean.TRUE) |
06 | .addToCoordinates(location); |
09 | kml.marshal( new File( "HelloKml.kml" )); |
10 | } catch (FileNotFoundException ex) { |
11 | Logger.getLogger(Main. class .getName()).log(Level.SEVERE, null , ex); |
In the future I will expand on this application to provide more information in the KML.
Hi.
ReplyDeleteI trying to use a code similar to yours, but I get errors in:
kml.createAndSetPlacemark()
.withName(placemarkName).withOpen(Boolean.TRUE)
.createAndSetPoint().addToCoordinates(-0.126236, 51.500152);
The method createAndSetPlacemark is undefined for the type Kml.
I'm using eclipse and I added libs:
activation.jar, jaxb, etc..
and JavaApiforKml.jar
but no way.
Could you please tell me what am I doing wrong.?
Thanks for your post (I thought I was wrong with my code)