我使用以下网址访问了J2ME中的谷歌地图:
String url =“http://maps.google.com/maps/api/staticmap?center=”+ lat +“,”+ lon +“& zoom =”+ zoom +“& size =”+ width +“x”+ height +“& maptype = roadmap”+与 “&标记=颜色:红色|标签:A |” + lat +“,”+ lon +“& sensor = true”;
我想使用此网址显示Snippet。
请告诉我将网址代码放在网址中的位置以及网址代码是什么?
亲切的问候,
Parmanand
答案 0 :(得分:0)
您可以使用以下代码下载图片:
private Image getImage(String url) {
ContentConnection c = null;
DataInputStream dis = null;
try {
try {
c = (ContentConnection) Connector.open(url);
int len = (int) c.getLength();
dis = c.openDataInputStream();
if (len > 0) {
byte[] data = new byte[len];
dis.readFully(data);
im = Image.createImage(data, 0, data.length);
}
} catch (IOException ioe) {
// Failed to read the url. Can't do anything about it, just don't
// update the image.
} finally {
// Regardless of whether we are successful, we need to close
// Connections behind us. Basic Housekeeping.
if (dis != null) {
dis.close();
}
if (c != null) {
c.close();
}
}
} catch (IOException ioe) {
// closure of connections may fail, nothing we can do about it.
}
}
Image
可以Form
显示为ImageItem
,例如:
ImageItem imgItem =
new ImageItem("Default: ", getImage(url),
Item.LAYOUT_CENTER, null,
Item.BUTTON);
顺便说一下,上面的代码段只能用于单个静态地图图片 - 不要试图覆盖Canvas.paint()
并使用它来动态更新地图 - 所需的数据流量是highly inefficient,并且可以使用替代解决方案(如此问题here中所述)。