gpt4 book ai didi

android - 如何在android中的每个标记(多个标记)上打开一个信息窗口?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:53:23 25 4
gpt4 key购买 nike

因为我使用的是 Google map v2,所以我想打开多个制造商的信息窗口。我用单个标记完成了此操作,还使用了 show info window();但它适用于最后一个标记并且只适用于一个标记。我只想要而且只想要在 android 中。

public class MainActivity extends FragmentActivity {

private GoogleMap googleMap;
private final LatLng HAMBURG = new LatLng(53.558, 9.927);
private final LatLng KIEL = new LatLng(53.551, 9.993);
private Marker marker;
private Hashtable<String, String> markers;
private ImageLoader imageLoader;
private DisplayImageOptions options;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();

initImageLoader();
markers = new Hashtable<String, String>();
imageLoader = ImageLoader.getInstance();

options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.ic_launcher) // Display Stub Image
.showImageForEmptyUri(R.drawable.ic_launcher) // If Empty image found
.cacheInMemory()
.cacheOnDisc().bitmapConfig(Bitmap.Config.RGB_565).build();

if ( googleMap != null ) {

googleMap.setInfoWindowAdapter(new CustomInfoWindowAdapter());

final Marker hamburg = googleMap.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
hamburg.showInfoWindow();
markers.put(hamburg.getId(), "http://img.india-forums.com/images/100x100/37525-a-still-image-of-akshay-kumar.jpg");

final Marker kiel = googleMap.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
markers.put(kiel.getId(), "http://www.yodot.com/images/jpeg-images-sm.png");
//kiel.showInfoWindow();

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}

private class CustomInfoWindowAdapter implements InfoWindowAdapter {

private View view;

public CustomInfoWindowAdapter() {
view = getLayoutInflater().inflate(R.layout.custom_info_window,
null);
}

@Override
public View getInfoContents(Marker marker) {

if (MainActivity.this.marker != null
&& MainActivity.this.marker.isInfoWindowShown()) {
MainActivity.this.marker.hideInfoWindow();
MainActivity.this.marker.showInfoWindow();
}
return null;
}

@Override
public View getInfoWindow(final Marker marker) {
MainActivity.this.marker = marker;

String url = null;

if (marker.getId() != null && markers != null && markers.size() > 0) {
if ( markers.get(marker.getId()) != null &&
markers.get(marker.getId()) != null) {
url = markers.get(marker.getId());
}
}
final ImageView image = ((ImageView) view.findViewById(R.id.badge));

if (url != null && !url.equalsIgnoreCase("null")
&& !url.equalsIgnoreCase("")) {
imageLoader.displayImage(url, image, options,
new SimpleImageLoadingListener() {
@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view,
loadedImage);
getInfoContents(marker);
}
});
} else {
image.setImageResource(R.drawable.ic_launcher);
}

final String title = marker.getTitle();
final TextView titleUi = ((TextView) view.findViewById(R.id.title));
if (title != null) {
titleUi.setText(title);
} else {
titleUi.setText("");
}

final String snippet = marker.getSnippet();
final TextView snippetUi = ((TextView) view
.findViewById(R.id.snippet));
if (snippet != null) {
snippetUi.setText(snippet);
} else {
snippetUi.setText("");
}

return view;
}
}

private void initImageLoader() {
int memoryCacheSize;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
int memClass = ((ActivityManager)
getSystemService(Context.ACTIVITY_SERVICE))
.getMemoryClass();
memoryCacheSize = (memClass / 8) * 1024 * 1024;
} else {
memoryCacheSize = 2 * 1024 * 1024;
}

final ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
this).threadPoolSize(5)
.threadPriority(Thread.NORM_PRIORITY - 2)
.memoryCacheSize(memoryCacheSize)
.memoryCache(new FIFOLimitedMemoryCache(memoryCacheSize-1000000))
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
.tasksProcessingOrder(QueueProcessingType.LIFO).enableLogging()
.build();

ImageLoader.getInstance().init(config);
}
}

最佳答案

默认标记一次只能显示一个信息窗口。但是,您可以使用 Maps Android 库轻松显示更多信息:https://developers.google.com/maps/documentation/android-api/utility/

这是一个例子:

IconGenerator iconFactory = new IconGenerator(this);
mMarkerA = mMap.addMarker(new MarkerOptions().position(new LatLng(12, 34)));
mMarkerA.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker A")));
mMarkerB = mMap.addMarker(new MarkerOptions().position(new LatLng(13, 35)));
mMarkerB.setIcon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon("Marker B")));

并添加

compile 'com.google.maps.android:android-maps-utils:0.4+'

到你的 gradle 文件。

关于android - 如何在android中的每个标记(多个标记)上打开一个信息窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23407059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com