import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; /** *

* This class demonstrates how to use the Goolgle Maps API with java. Google * Maps is based on Javascript which is similar to, but not the same as, Java. * This class writes an html file to disk and then launches an external web * browser to view the map. *

*

* This code is based on an example from the Google Maps website:
* http://code.google.com/apis/maps/documentation/examples/marker-simple.html * * The documentation for all things related to Google Maps is in the Google * Maps API: http://code.google.com/apis/maps/documentation/ *

* *

* * @author Mark Woehrer; edited by Wayne Smith, 4/2009 * @version 1a5 */ public class Driver { /** * The content is stored in a template containing placeholders for the * various points of interest (and the zoom factor). A simple search and * replace operation is performed replacing each placeholder with the * appropriate javascript. */ private String content; public Driver() throws IOException { super(); /* * The content contains four placeholders; one for the center point, zoom * level, zip point, and contact list. The placeholders are the names * surrounded by underscores. For example, the placeholder for the * center point is _center_point_. * * Other map attributes may be changed by directly modifying the * template. For example, to change the icon used, * you could do something like: * * // Create our "tiny" marker icon * var blueIcon = new GIcon(G_DEFAULT_ICON); * blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png"; * * // Set up our GMarkerOptions object * markerOptions = { icon:blueIcon }; * * (Pulled from http://code.google.com/apis/maps/documentation/overlays.html#Icons_overview) */ content = "\n" + "\n" + " \n" + " \n" + " Google Maps JavaScript API Example: Simple PushPins\n" + " \n" + " \n" + " \n" + " \n" + "

\n" + "
\n" + " \n" + ""; /* * The following code replaces each of the placeholders in the content * string with the appropriate Javascript. Notice that the Javascript is * generated using the toString() method from each Java object */ // Set the center point LatLng center_point = new LatLng(30.030819, -91.07576); content = content.replaceAll("_center_point_", center_point.toString()); // Set the zoom level int zoom = 2; content = content.replaceAll("_zoom_", Integer.toString(zoom)); // Set a single contact point LatLng point = new LatLng(31.030819, -91.07576); content = content.replaceAll("_point_", point.toString()); // Set the list of contacts ContactBook contactBook = new ContactBook(); contactBook.addContact(new LatLng(10.8, -35.5)); contactBook.addContact(new LatLng(25.6, -67.0)); contactBook.addContact(new LatLng(29.2, -91.3)); content = content.replaceAll("_array_", contactBook.toString()); // Save to disk BufferedWriter writer = new BufferedWriter(new FileWriter("out.html")); writer.write(content); writer.flush(); // Open in external browser // Runtime.getRuntime().exec("open out.html"); // Mac Runtime.getRuntime().exec("firefox out.html"); // UNIX/Linux //Runtime.getRuntime().exec("C:/Program Files/Mozilla Firefox/firefox.exe out.html"); // Windows } /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub @SuppressWarnings("unused") Driver driver = new Driver(); } }