【发布时间】:2014-10-07 18:45:55
【问题描述】:
我是新手,我正在开发一个跟踪员工位置并将其显示在地图上的 Android 应用程序。它几乎完成了,只是它没有在标记上显示员工的图像。
我能够在网络上下载图像并将该图像设置在标记上。但问题是,它不会自动显示。我需要再次绘制坐标才能显示图像。这是我用来下载并在标记上设置图像的代码...
private class DownloadEmployeeImage extends AsyncTask<String, Void, Bitmap> {
ImageView image;
public DownloadEmployeeImage(ImageView bmImage) {
this.image = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String url = urls[0];
Bitmap bmpImg = null;
try {
InputStream in = new java.net.URL(url).openStream();
bmpImg = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Failed to download image: ", e.toString());
}
return bmpImg;
}
protected void onPostExecute(Bitmap bmpImg) {
try {
image.setImageBitmap(RoundedImageView.getCroppedBitmap(bmpImg, 200));
} catch(Exception e) {
image.setImageBitmap(RoundedImageView.getCroppedBitmap(BitmapFactory
.decodeResource(MainActivity.this.getResources(), R.drawable.ic_user_placeholder), 200));
}
}
}
下载并设置标记上的图像后,我在地图上添加了标记
View viewLocationMarker = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.layout_location_marker, null);
ImageView ivPictureLocationMarker = (ImageView) viewLocationMarker.findViewById(R.id.ivPictureLocationMarker);
new DownloadEmployeeImage(ivPictureLocationMarker).execute(TheURLOfTheImage);
Marker locationMarker = googleMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude)).title(name).anchor(0.33f, 1)
.icon(BitmapDescriptorFactory.fromBitmap(TarkieManagerLib
.createDrawableFromView(MainActivity.this, viewLocationMarker))));
关于如何做到这一点的任何绝妙主意?
【问题讨论】:
标签: android google-maps-android-api-2