import world.World; import image.*; /** Represents a Map of a location (thanks to Google[tm]) */ public class Map{ String base = "http://maps.google.com/maps/api/staticmap?"; int zoom = 12; // Header String title; // Center Location double lat; double lon; // Size int width; int height; // Put Marker? boolean marker; /** Create a Map with the given title that displays the given lat/long (with the * given size in pixels) with or without a "marker". */ public Map(String title, double lat, double lon, int width, int height, boolean marker){ this.title = title; this.lat = lat; this.lon = lon; this.width = width; this.height = height; this.marker = marker; } /** Retrieve this Map's Image (from Google). Returns an image, which can be * displayed using {@link world.World#display(Image) World.display(Image)}. */ public Image getImage(){ Image tImg = new Text(this.title, 30, "black"); return new EmptyScene(this.width+2, this.height+40+1) .placeImage(this.mapImage(), this.width/2+1, this.height/2+40) .placeImage(tImg, this.width/2, 30); } /** Get the map image for this Map... no title, just what Google provides */ private Image mapImage(){ String url = (this.base+ "center="+this.lat+","+this.lon+"&"+ "size="+this.width+"x"+this.height+"&"+ "zoom="+this.zoom); // Add a marker? if(this.marker) return new FromURL(url+"&markers=color:blue|center|"+ this.lat+","+this.lon+"&sensor=false"); else return new FromURL(url+"&sensor=false"); } // Simple little test... show Boston public static void main(String[] args){ World.display(new Map("Albany", 42.65,-73.75, 200, 200, false).getImage()); } }