我是新手,我正在开发一个跟踪员工位置并在地图上显示他们的android应用程序。这几乎完成了,只是它不显示员工在标记上的图像。刷新google地图上的标记以查看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))));
任何我该如何做到这一点的绝妙主意?
不错!它的作用就像一种魅力。谢谢! – mgcaguioa 2014-10-07 11:14:13