我想使用Google Maps Android API V2上可用的落伍功能。我要显示为覆盖的图像仅在线提供(因为定期更新);我不能使用本地资源。Google提供的示例仅显示了如何使用本地资源:
mGroundOverlay = mMap.addGroundOverlay(new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922)).anchor(0, 1)
.position(NEWARK, 8600f, 6500f));
如何通过URL使用在线图像?最好的方法是什么?
我已经使用了一个asynctask,其中在doinbackground()方法中我下载了图像和onpostexecute()我添加了下载的doctoverlay
URL url = new URL(strUrl);
InputStream is = (InputStream) url.getContent();
byte[] buffer = new byte[8192];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while ((bytesRead = is.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
downloadedBmp = BitmapFactory.decodeByteArray(output.toByteArray(), 0, output.toByteArray().length);