【发布时间】:2020-12-03 03:54:38
【问题描述】:
您好,我正在使用 java、huawei 地图和 firebase 在 android 中创建应用程序,但我有一个几天无法解决的问题是,当按下地图标记并在 TextView 中显示数据时,它只显示最后一条记录我的数据库而不是我选择的标记。
public void listarMarcadores(DataSnapshot dataSnapshot) {
try {
final String key = dataSnapshot.getKey();
HashMap<String, Object> value = (HashMap<String, Object>) dataSnapshot.getValue();
double lat;
double lon;
final String nombre;
final String tipo;
final String descripcion;
lat = Double.parseDouble(value.get("latitud").toString());
lon = Double.parseDouble(value.get("longitud").toString());
nombre = (String) value.get("nombre_puesto");
tipo = (String) value.get("tipo_ambulante");
descripcion = (String) value.get("descripcion");
LatLng ubicacion = new LatLng(lat, lon);
Marker mimarker;
hMap.setOnMarkerClickListener(new HuaweiMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
txtKey.setText(key);
txtNombre_puesto.setText(nombre);
txtDescripcion.setText(descripcion);
txtTipo.setText(tipo);
//, txtDireccion, txtHorario
mBottomSheetBehavior1.setState(BottomSheetBehavior.STATE_EXPANDED);
return false;
}
});
if (!mMarkers.containsKey(key)) {
if (tipo.equals("cevicheria")) {
mimarker = hMap.addMarker(new MarkerOptions().title(key).position(ubicacion).icon(BitmapDescriptorFactory.fromResource(R.drawable.pescado)));
mMarkers.put(key, mimarker).setIcon(BitmapDescriptorFactory.fromResource(R.drawable.pescado));
}
if (tipo.equals("chicharroneria")) {
mimarker = hMap.addMarker(new MarkerOptions().title(key).position(ubicacion).icon(BitmapDescriptorFactory.fromResource(R.drawable.cerdo)));
mMarkers.put(key, mimarker).setIcon(BitmapDescriptorFactory.fromResource(R.drawable.cerdo));
;
} else {
mimarker = hMap.addMarker(new MarkerOptions().title(key).position(ubicacion));
mMarkers.put(key, mimarker);
}
}
} catch (Exception e) {
Toast.makeText(this, "Error al listar marcadores", Toast.LENGTH_SHORT).show();
}
}
【问题讨论】:
-
在使用Huawei Map Kit之前,你有没有先integrate the HMS SDK进入你的Android Studio?顺便说一句,Map Kit 支持的设备只有华为设备。
-
雪莉是的,我愿意
-
谷歌地图或华为地图无法获取标记?如果您使用华为地图套件对标记进行聚类,建议您使用该工具:github.com/billtom20/3rd-maps-utils
标签: java android firebase google-maps huawei-mobile-services