android - MarkerOnClick 数据为空
问题描述
我正在设置标记如下,我可以在地图上看到标记
if (googleMap != null && mapFragment != null && googleMap.getProjection() != null) {
googleMap.addMarker(new MarkerOptions().position(new LatLng(
Double.parseDouble(storesWithDistance.getLatitude() + ""), Double.parseDouble(storesWithDistance.getLongitude() + "")
)).title(storesWithDistance.getStoreName() + "").snippet(i + ""));
}
`marker.getTitle()` is returning `null` ..... Why is it happening ?
@Override
public boolean onMarkerClick(Marker marker) {
try {
if (googleMap != null && mapFragment != null && googleMap.getProjection() != null) {
String title = marker.getTitle();
String snippet = marker.getSnippet();
Log.d("","");
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
解决方案
你实现了接口GoogleMap.OnMarkerClickListener吗?你添加了这一行吗?:
googleMap.setOnMarkerClickListener(this)
如果你试图把你String title = marker.getTitle();
的try..catch块放在外面并用 Log.d() 测试它怎么办?
推荐阅读
- ruby-on-rails - 如果哈希值是字符串,Ruby/Rails 返回哈希元素
- php - 无法向数据库插入数据 | 致命错误:未捕获的 PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064
- visual-studio-code - Why does debugging with lldb in VSCode garble chinese characters?
- java - How can I draw over a GridPane of Rectangles with an Image? (JavaFX)
- asp.net - Module with shared state
- python - 如何删除嵌套在其他双引号正则表达式中的双引号
- git - How do I clone only a subdirectory of a Git repo?
- python - 如何去元组 *args
- r - R - GGplot2 Barplot - Fixing colors of color palette to same values over multiple plots
- r - 我如何在 R 中实现这个代数和?