gpt4 book ai didi

android - 获取自定义标题标记信息谷歌地图

转载 作者:行者123 更新时间:2023-11-30 00:43:58 24 4
gpt4 key购买 nike

您好,我正在使用谷歌地图,我在我拥有的标记上创建了一个自定义标题,我需要知道何时选择了一个标记,因为我需要打开一个 fragment ,所以我该如何获取标题上的信息有了这些信息,让我把我得到的代码贴给你:

 @Override
public void onMapReady(GoogleMap googleMap) {
map =googleMap;
map.getUiSettings().setZoomControlsEnabled(true);


for (Taxi taxi : taxis) {
u= taxi.getUbicacionActual();
LatLng ubicacion= new LatLng(Double.parseDouble(u.getLatitud()), Double.parseDouble(u.getLongitud()));


map.moveCamera(CameraUpdateFactory.newLatLngZoom(ubicacion,15));

MarkerOptions punto= new MarkerOptions().position(ubicacion);
map.addMarker(punto);

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {

return null;
}

@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_title, null);


TextView info1 = (TextView) v.findViewById(R.id.info1);
TextView info2 = (TextView) v.findViewById(R.id.info2);
TextView info3 = (TextView) v.findViewById(R.id.info3);

info1.setText("Fecha: " + u.getFecha());
info3.setText("Longitud: " + u.getLongitud().toString());

info2.setText("Ubicacion: "+obtenerDireccion(u.getLatitud(),u.getLongitud()));

return v;
}
});


}
map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {

Fragment fragmento;
fragmento = new HistorialFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_principal, fragmento)
.commit();


}
});

在我调用新 fragment 的 OnInfoWindowClickListener 方法上,我需要从自定义标题发送信息,有人可以帮我解决这个问题吗?

最佳答案

试试这个:

getInfoContents(Marker marker) 方法中添加您的 setOnInfoWindowClickListener:

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {

return null;
}

@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_title, null);


final TextView info1 = (TextView) v.findViewById(R.id.info1);
TextView info2 = (TextView) v.findViewById(R.id.info2);
TextView info3 = (TextView) v.findViewById(R.id.info3);

info1.setText("Fecha: " + u.getFecha());
info3.setText("Longitud: " + u.getLongitud().toString());

info2.setText("Ubicacion: "+obtenerDireccion(u.getLatitud(),u.getLongitud()));

map.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
public void onInfoWindowClick(Marker marker)
{
Fragment fragmento;
fragmento = new HistorialFragment();
Bundle bundle = new Bundle();
bundle.putString("title",info1.getText().toString());
fragmento.setArguments(bundle);
getSupportFragmentManager().beginTransaction()
.replace(R.id.content_principal, fragmento)
.commit();
}
});

return v;
}
});

关于android - 获取自定义标题标记信息谷歌地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42096643/

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