[英]Custom marker in google maps in android
我想在谷歌地圖的標記中添加圖片。 我想在單擊標記圖片后顯示該圖片的右側一些文本。 我使用以下代碼創建標記:
Marker melbourne = map.addMarker(new MarkerOptions()
.position(new LatLng(lblat,
lbLong))
.title("Melbourne")
.snippet("Population: 4,137,400")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
但在那個解決方案中,我只有標題和片段。 我的路上怎么做標記?
你將不得不抬高自己的布局InfoWindow
與InfoWindowAdapter
。 請參閱此處的文檔。
這是一個小例子(我在我的地圖Activity
將此作為內部類):
class MyInfoWindowAdapter implements InfoWindowAdapter {
private final View v;
MyInfoWindowAdapter() {
v = getLayoutInflater().inflate(R.layout.infowindow,
null);
}
@Override
public View getInfoContents(Marker marker) {
ImageView icon = (ImageView) v.findViewById(R.id.icon);
// set some bitmap to the imageview
return v;
}
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
}
在你的地圖Activity
gmap.setInfoWindowAdapter(new MyInfoWindowAdapter());
祝你好運 :)
如果要使用圖像自定義標記,可以將此圖像添加到 drawable 文件夾,然后:
mMap.addMarker(new MarkerOptions()
.position(marq).icon(BitmapDescriptorFactory.fromResource((R.drawable.thenameofyourimage)))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.