【发布时间】:2013-03-13 15:37:20
【问题描述】:
我正在构建一个 Android GPS 应用程序,该应用程序根据用户当前位置显示最近的地点。我正在使用 MapFragment,并且在 AsyncTask 中像这样在地图上放置标记:
protected void onPostExecute(Void result) {
super.onPostExecute(result);
for(int i = 0; i < list.size(); i++)
{
HashMap<String,String> location = new HashMap<String,String>();
location = list.get(i);
String type = location.get("type");
int marker = getTypeDrawable(type);
LatLng position = new LatLng(Float.parseFloat(location.get("lat")), Float.parseFloat(location.get("long")));
map.addMarker(new MarkerOptions()
.position(position)
.title(location.get("name"))
.snippet(location.get("distance") + location.get("type"))
.icon(BitmapDescriptorFactory.fromResource(marker)));
System.out.println(list.get(i));
}
Toast.makeText(MainActivity.this, "Finished retrieving nearby locations",
Toast.LENGTH_SHORT).show();
}
这是我的全局变量列表,其中包含最近位置的所有信息:ArrayList<HashMap<String, String>> list;
我的计划是在我单击标记时显示一个弹出对话框,就像地理缓存应用程序“C:Geo”一样。我的问题是,我不知道如何在对话框中显示该标记的信息。如您所见,我正在使用map.addMarker() 方法,但我无法将该位置与该标记相关联。
我希望制作一个这样的弹出对话框:
@Override
public boolean onMarkerClick(Marker marker) {
//Get location associated with marker.
//Fill popup dialog with information associated
//with location and then invoke the dialog.
}
【问题讨论】:
标签: android object location google-maps-markers google-maps-android-api-2