How to make Google Map more useful on your phone if you don't have GPS function? Here are something I found hard to use Google Map on your phone:
1. Zoom In/Out
2.
Source Code:
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.Canvas.*;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
public class ImageMonkey extends MIDlet implements CommandListener, Runnable {
/*
* A reference to the MIDlet's Display object
*/
private Display mDisplay;
/*
* A form for displaying an image
*/
private Form mForm;
String url= "http://itp.nyu.edu/~htt213/Mobile/MapITP_01.png";
/*
* Constructor
*/
public ImageMonkey() {
mForm = new Form("Connecting...");
mForm.addCommand(new Command("Exit", Command.EXIT, 0));
mForm.setCommandListener(this);
}
public void startApp() {
if (mDisplay == null)
mDisplay = Display.getDisplay(this);
mDisplay.setCurrent(mForm);
// Run network operations in a separate thread.
Thread t = new Thread(this);
t.start();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c.getCommandType() == Command.EXIT)
notifyDestroyed();
}
class KeyFinderCanvas extends Canvas {
int lastKeyCode = 0;
protected void keyPressed(int keyCode) {
lastKeyCode = keyCode;
System.out.println("Key Pressed");
}
protected void paint(Graphics g) {
if (lastKeyCode == 38){
url = "http://itp.nyu.edu/~htt213/Mobile/MapITP_01.png";
g.drawString("Zoom Out", getWidth()/2, getHeight()/2,
Graphics.BASELINE|Graphics.HCENTER);
System.out.println("Zoom Out!");
}
if (lastKeyCode == 40){
url = "http://itp.nyu.edu/~htt213/Mobile/MapITP_02.png";
g.drawString("Zoom in", getWidth()/2, getHeight()/2,
Graphics.BASELINE|Graphics.HCENTER);
System.out.println("Zoom In!");
}
}
}
public void run() {
HttpConnection hc = null;
DataInputStream in = null;
try {
/*
* We're going to read in a URL from the JAD file
* We could just as easily do something like this:
* String url = "http://website.com/mynewurl";
*/
//String url = getAppProperty("ImageMonkey-URL");
//String url = "http://itp.nyu.edu/~htt213/Mobile/MapITP_01.png";
System.out.println("Getting Map!");
hc = (HttpConnection) Connector.open(url);
int length = (int) hc.getLength();
byte[] data = null;
if (length != -1) {
System.out.println("Content Length is " + length);
data = new byte[length];
in = new DataInputStream(hc.openInputStream());
in.readFully(data);
}
else {
// If content length is not given, read in chunks.
int chunkSize = 512;
int index = 0;
int readLength = 0;
in = new DataInputStream(hc.openInputStream());
data = new byte[chunkSize];
do {
if (data.length < index + chunkSize) {
byte[] newData = new byte[index + chunkSize];
System.arraycopy(data, 0, newData, 0, data.length);
data = newData;
}
System.out.println(".");
readLength = in.read(data, index, chunkSize);
index += readLength;
} while (readLength == chunkSize);
length = index;
}
Image image = Image.createImage(data, 0, length);
ImageItem imageItem = new ImageItem(null, image, 0, null);
mForm.append(imageItem);
mForm.setTitle("Try using arrow key to zoom in");
}
catch (IOException ioe) {
StringItem stringItem = new StringItem(null, ioe.toString());
mForm.append(stringItem);
mForm.setTitle("Done.");
}
finally {
try {
if (in != null)
in.close();
if (hc != null)
hc.close();
} catch (IOException ioe) {
}
}
}
}
EasyMap-Google Map Hack
Tuesday, October 2, 2007Posted by Unknown at 7:18 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment