我想使用GroundOverlay提供的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));
如何通过网址使用在线图片?什么是最好的方式?
答案 0 :(得分:0)
我使用了AsyncTask,在doInBackground()方法中我下载了图像,在onPostExecute()中我将GroundOverlay与下载的位图一起添加
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);