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://www.google.com/apis/maps/documentation/examples/polyline-simple.html
*
*
* Here is a link to an existing hurricane tracker using Google Maps:
* http://stormadvisory.org/map/atlantic/
*
*
*
* @author Mark Woehrer
* @version 1a4
*/
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 for the center point, zoom
* level, zip point, and storm track. 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 width of the path from 5 to 10
* you must modify the third argument in the GPolyline constructor.
*/
content = "\n"
+ "\n"
+ "
\n"
+ " \n"
+ " Google Maps JavaScript API Example: Simple Polyline\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 the zip point
LatLng point = new LatLng(31.030819, -91.07576);
content = content.replaceAll("_point_", point.toString());
// Set the storm track
StormTrack track = new StormTrack();
track.addSample(new LatLng(10.8, -35.5));
track.addSample(new LatLng(25.6, -67.0));
track.addSample(new LatLng(29.2, -91.3));
content = content.replaceAll("_array_", track.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();
}
}