我正在使用Google Maps Android API。我使用了MarkerOptions,其中我将以下代码显示Icon作为PIN,距离和标题。现在我想在对话框中显示图像。下面给出了我希望它的图像。
final MarkerOptions markerOptions = new MarkerOptions();
JSONObject jPlace = arrayOfPlaces.getJSONObject(i);
if (!jPlace.isNull("title")) {
place = jPlace.getString("title");
}
if (!jPlace.isNull("urlhtml")) {
icon = jPlace.getString("urlhtml");
}
if (!jPlace.isNull("id")) {
distance = jPlace.getString("id");
}
if (!jPlace.isNull("distance")) {
distance = jPlace.getString("distance");
}
longitude = jPlace.getJSONObject("location").getString("lon");
latitude = jPlace.getJSONObject("location").getString("lat");
double lat = Double.parseDouble(latitude);
double lng = Double.parseDouble(longitude);
LatLng latLng = new LatLng(lat, lng);
markerOptions.position(latLng);
markerOptions.title(place);
markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_x));
mMap.addMarker(markerOptions).setSnippet("Distance "+distance);
mMap.addMarker(markerOptions).showInfoWindow();
当前图片:
所需图片:
答案 0 :(得分:0)
试试这个,创建自定义InfoWindowAdapter
public class MyCustomAdapterForItems implements InfoWindowAdapter {
private final View myContentsView;
MyCustomAdapterForItems() {
myContentsView = getLayoutInflater().inflate(
R.layout.map_info_window_dialog, null);
}
@Override
public View getInfoContents(Marker marker) {
return null;
}
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
TextView tvTitle = ((TextView) myContentsView
.findViewById(R.id.txtHeader));
TextView tvSnippet = ((TextView) myContentsView
.findViewById(R.id.txtAddress));
ImageView mImageView = (ImageView) myContentsView
.findViewById(R.id.mStoreImage);
final ProgressBar mProgress = (ProgressBar) myContentsView
.findViewById(R.id.mProgress);
tvTitle.setTypeface(mTyFaceHelvetica);
tvSnippet.setTypeface(mTyFaceHelvetica);
if (clickedClusterItem != null) {
tvTitle.setText(Html.fromHtml(clickedClusterItem
.getmOfferTitle()));
tvSnippet.setText(Html.fromHtml(clickedClusterItem
.getmOfferDesc()));
Log.e("Coupon Image URL : ",
"" + clickedClusterItem.getmCouponImageURL());
mImageLoader.displayImage(
clickedClusterItem.getmCouponImageURL(), mImageView,
Utils.Options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri,
View view) {
mProgress.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri,
View view, FailReason failReason) {
mProgress.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
mProgress.setVisibility(View.GONE);
}
});
// ImageLoader.getInstance().displayImage(
// clickedClusterItem.getmCouponImageURL(), mImageView,
// Utils.Options);
}
return myContentsView;
}
}
将自定义适配器设置为Googlemap
google_map.setInfoWindowAdapter(new MyCustomAdapterForItems());