gpt4 book ai didi

android - 显示 infowindow android map

转载 作者:行者123 更新时间:2023-11-30 02:46:01 25 4
gpt4 key购买 nike

如何在加载 map 时显示标记信息窗口?当我点击 map 名称时,一个新的 Activity 在 map 加载的地方开始。它显示标记,问题是我想自动显示我创建的自定义信息窗口。下面是我的代码:我会为那些可以修复的人标记这个答案这。谢谢。

if (nameList.get(i).equals(selected)){

Marker marker = map.addMarker(new MarkerOptions()
.title(nameList.get(i))
.snippet(addressList.get(i))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_location))
.position(new LatLng(latList.get(i), lngList.get(i))));

marker.showInfoWindow();

//Set Custom InfoWindow
map.setInfoWindowAdapter(new InfoWindowAdapter() {


@Override
public View getInfoWindow(Marker arg0) {



return null;
}

@Override
public View getInfoContents(Marker marker) {

View myContentsView = getLayoutInflater().inflate(R.layout.map_info, null);

TextView tvTitle = ((TextView)myContentsView.findViewById(R.id.title));
tvTitle.setText(marker.getTitle());

TextView tvSnippet = ((TextView)myContentsView.findViewById(R.id.snippet));
tvSnippet.setText(marker.getSnippet());

TextView infoSnippet = (TextView)myContentsView.findViewById(R.id.moreinfo);
infoSnippet.setText("Click for more details.");

return myContentsView;
}
});

//Open New Activity
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

@Override
public void onInfoWindowClick(Marker marker) {

Intent intent = new Intent(SelectedPlaceActivity.this, PlaceDescriptionActivity.class);
intent.putExtra("placetitle", marker.getTitle().toString());
intent.putExtra("snippet", marker.getSnippet().toString());
startActivity(intent);

}
});


}

最佳答案

看来您需要一个InfoWindow 适配器。请参阅以下示例:

map.setInfoWindowAdapter(new InfoWindowAdapter(){
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker marker) {
return null;
}

// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker marker) {

// Getting view from the layout file info_window_layout
View v = getLayoutInflater().inflate(R.layout.custom_info_window, null);

// Getting reference to the TextView to set title
TextView note = (TextView) v.findViewById(R.id.note);
note.setText(marker.getTitle() );

return v;
}
});

如您所见,您需要创建自定义布局。在我的示例中:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView android:id="@+id/note"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textColor="#000000"/>

<ImageButton android:id="@+id/takeMeThere"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/note"
android:contentDescription="@string/directions"
android:src="@drawable/ic_action_directions"
android:background="@null"/>
</RelativeLayout>

希望对你有帮助

关于android - 显示 infowindow android map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25007041/

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