我是新手,我正在開發一個跟蹤員工位置並在地圖上顯示他們的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