我有这样的代码:
protected void onPostExecute(final ArrayList<HashMap<String, String>> adapter) {
for (final HashMap<String, String> a : adapter) {
LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)), Double.valueOf(a.get(TAG_longitude)));
Log.e("pppppos", String.valueOf(pos.latitude));
Marker m = map.addMarker(new MarkerOptions().position(pos)
.title(a.get(TAG_NAME))
.snippet("Kiel is cool"));
map.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
Intent nextScreen = new Intent(SearchExchangerActivity.this, BankExchangersListActivity.class);
nextScreen.putExtra("exchanger_id", id);
startActivityForResult(nextScreen, 0);
}
});
}
但是我需要将每个标记的用户不可见字段设置为例如Tag_id
,然后在发送额外信息到其他活动时使用此id,类似于:
但是我需要为每个标记设置一个对用户不可见的字段,例如Tag_id
,并在将额外信息发送到其他活动时使用该字段,类似于:
protected void onPostExecute(final ArrayList<HashMap<String, String>> adapter) {
for (final HashMap<String, String> a : adapter) {
LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)), Double.valueOf(a.get(TAG_longitude)));
Marker m = map.addMarker(new MarkerOptions().position(pos)
.title(a.get(TAG_NAME))
.snippet("Kiel is cool")
.Tag_id(TAG_ID));
map.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(Marker marker){
Intent nextScreen = new Intent(SearchExchangerActivity.this, BankExchangersListActivity.class);
nextScreen.putExtra("exchanger_id", marker.get(TAG_ID));
startActivityForResult(nextScreen, 0);
}
});
}
这可行吗?我该如何在我的听众中获取我点击的标记?
也可以通过标题字段完成... 但是当我编写 marker.getTitle()
时,会出现错误...
更新
for (final HashMap<String, String> a : adapter) {
LatLng pos = new LatLng(Double.valueOf(a.get(TAG_latitude)), Double.valueOf(a.get(TAG_longitude)));
Log.e("pppppos", String.valueOf(pos.latitude));
HashMap<Marker, String> m = new HashMap<Marker, String>();
m.put( map.addMarker(new MarkerOptions().position(pos)
.title(a.get(TAG_NAME))
.snippet("Kiel is cool")), "1");
}
map.setOnInfoWindowClickListener(
new OnInfoWindowClickListener(){
public void onInfoWindowClick(HashMap<Marker, String> marker){
Intent nextScreen = new Intent(SearchExchangerActivity.this, BankExchangersListActivity.class);
nextScreen.putExtra("exchanger_id", "1");
startActivityForResult(nextScreen, 0);
}
});
Marker
参数指的是一个完全不同的对象,但是Marker
的equals
和hashCode
方法返回的值与从addMarker
方法中最初返回的对象相同。因此,Map
将返回正确的模型(所讨论的String
对象)。如果这对你不起作用,请在你的代码中寻找错误。同时阅读这篇文章。 - MaciejGórski