大佬教程收集整理的这篇文章主要介绍了使标记带有自定义信息,以供单击时使用(Android,Google Maps v2),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
定义一个以 *
public class AlertVIEwOnMap extends Activity {
//declarations
ArrayList<String> dateCreatedAtList = new ArrayList<String>();
TextVIEw busnumberTextVIEw;
TextVIEw descriptiontextVIEw;
TextVIEw alertTimeTextVIEw;
DateFormat dateFormat = new SimpleDateFormat("HH:mm");
private HashMap<Marker,Alert> markerDataMap;
protected voID onCreate(Bundle savedInstanceStatE) {
// Todo auto-generated method stub
super.onCreate(savedInstanceStatE);
this.setContentVIEw(com.fourBox.bocterapp.R.layout.details_design);
busnumberTextVIEw = (TextVIEw) findVIEwByID(R.ID.textVIEwAlertBusnumber);
descriptiontextVIEw = (TextVIEw) findVIEwByID(R.ID.textVIEwAlertDescription);
alertTimeTextVIEw = (TextVIEw) findVIEwByID(R.ID.textVIEwAlertTimE);
busnumber = geTintent().getIntextra("busnumber", 0);
description = geTintent().getStringExtra("description");
coordinatesLatitude = geTintent().getDoubleExtra("coordinatesLatitude", 0);
coordinatesLongitude = geTintent().getDoubleExtra("coordinatesLongitude", 0);
alertTime.setTime(geTintent().getLongExtra("createdAt", 0));
busnumberList = geTintent().getStringArrayListExtra("busnumberList");
descriptionList = geTintent().getStringArrayListExtra("descriptionList");
coordinatesLatitudeList = geTintent().getStringArrayListExtra("coordinatesLatitudeList");
coordinatesLongitudeList = geTintent().getStringArrayListExtra("coordinatesLongitudeList");
dateCreatedAtList = geTintent().getStringArrayListExtra("dateCreatedAtList");
GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentByID(com.fourBox.bocterapp.R.ID.mapFragment)).getMap();
reunitealertListFromGetExtra();
placeAllMarkersOnMap(mMap, alertsList);
LatLng latLng = new LatLng(coordinatesLatitude, coordinatesLongitudE);
Cameraposition cameraposition = new Cameraposition.builder()
.target(latLng) // Center Set
.zoom(18.0f) // Zoom
.bearing(0) // OrIEntation of the camera to east
.tilt(30) // Tilt of the camera to 30 degrees
.build(); // Creates a Cameraposition from the builder
mMap.animateCamera(CameraupdateFactory.newCameraposition(cameraposition));
busnumberTextVIEw.setText(String.valueOf(busnumber));
descriptiontextVIEw.setText(description);
alertTimeTextVIEw.setText(String.valueOf(dateFormat.format(alertTimE)));
}
public voID placeAllMarkersOnMap(GoogleMap mMap, ArrayList<Alert> alertsList) {
markerDataMap = new HashMap<Marker, Alert>();
for(int i=0; i<alertsList.size(); i++) {
markerDataMap.put(mMap.addMarker(new MarkerOptions()
.position(new LatLng(alertsList.get(i).getCoordinates().getLatitude(), alertsList.get(i).getCoordinates().getLongitude()))
.title(alertsList.get(i).getDescription())
.snippet(String.valueOf(alertsList.get(i).getBusnumber())
)),alertsList.get(i));
}
}
public voID reunitealertListFromGetExtra() {
for (int i =0; i<busnumberList.size(); i++) {
Alert alert = new Alert();
ParseGeoPoint parseGeoPoint = new ParseGeoPoint();
parseGeoPoint.setLatitude(Double.valueOf(coordinatesLatitudeList.get(i)));
parseGeoPoint.setLongitude(Double.valueOf(coordinatesLongitudeList.get(i)));
alert.setBusnumber(Integer.valueOf(busnumberList.get(i)));
alert.setDescription(descriptionList.get(i));
alert.setCoordinates(parseGeoPoint);
alert.setCreatedAt(new Date(Long.valueOf(dateCreatedAtList.get(i))));
alertsList.add(alert);
}
}
public GoogleMap.onMarkerClickListener geTinfoMarkerClickListener() {
return new GoogleMap.onMarkerClickListener() {
@OverrIDe
public Boolean onMarkerClick(Marker marker) {
Alert alert = markerDataMap.get(marker);
busnumberTextVIEw.setText(alert.getDescription());
descriptiontextVIEw.setText(alert.getBusnumber());
alertTimeTextVIEw.setText(dateCreatedAtList.get(alert.getID()));
marker.showInfoWindow();
return true;
}
};
}
}
我有以下代码:
public class AlertViewOnMap extends Activity {
//declarations
ArrayList<String> dateCreatedAtList = new ArrayList<String>();
TextView busnumberTextView;
TextView descriptiontextView;
TextView alertTimeTextView;
DateFormat dateFormat = new SimpleDateFormat("HH:mm");
protected void onCreate(Bundle savedInstanceStatE) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceStatE);
this.setContentView(com.fourbox.bocterapp.R.layout.details_design);
busnumberTextView = (TextView) findViewById(R.id.textViewAlertBusnumber);
descriptiontextView = (TextView) findViewById(R.id.textViewAlertDescription);
alertTimeTextView = (TextView) findViewById(R.id.textViewAlertTimE);
busnumber = geTintent().getIntextra("busnumber",0);
description = geTintent().getStringExtra("description");
coordinatesLatitude = geTintent().getDoubleExtra("coordinatesLatitude",0);
coordinatesLongitude = geTintent().getDoubleExtra("coordinatesLongitude",0);
alertTime.setTime(geTintent().getLongExtra("createdAt",0));
busnumberList = geTintent().getStringArrayListExtra("busnumberList");
descriptionList = geTintent().getStringArrayListExtra("descriptionList");
coordinatesLatitudeList = geTintent().getStringArrayListExtra("coordinatesLatitudeList");
coordinatesLongitudeList = geTintent().getStringArrayListExtra("coordinatesLongitudeList");
dateCreatedAtList = geTintent().getStringArrayListExtra("dateCreatedAtList");
GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager().findFragmentById(com.fourbox.bocterapp.R.id.mapFragment)).getMap();
reuniteAlertListFromGetExtra();
placeAllMarkersOnMap(mMap,alertsList);
LatLng latLng = new LatLng(coordinatesLatitude,coordinatesLongitudE);
CameraPosition cameraPosition = new CameraPosition.builder()
.target(latLng) // Center Set
.zoom(18.0f) // Zoom
.bearing(0) // Orientation of the camera to east
.tilt(30) // Tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMap.animateCamera(CameraupdateFactory.newCameraPosition(cameraPosition));
busnumberTextView.setText(String.valueOf(busnumber));
descriptiontextView.setText(description);
alertTimeTextView.setText(String.valueOf(dateFormat.format(alertTimE)));
}
public void placeAllMarkersOnMap(GoogleMap mMap,ArrayList<Alert> alertsList) {
for(int i =0; i<alertsList.size(); i++) {
mMap.addMarker(new MarkerOptions()
.position(new LatLng(alertsList.get(i).getCoordinates().getLatitude(),alertsList.get(i).getCoordinates().getLongitude()))
.title(alertsList.get(i).getDescription())
.snippet(String.valueOf(alertsList.get(i).getBusnumber())
));
}
}
public void reuniteAlertListFromGetExtra() {
for (int i =0; i<busnumberList.size(); i++) {
Alert alert = new Alert();
ParseGeoPoint parseGeoPoint = new ParseGeoPoint();
parseGeoPoint.setLatitude(Double.valueOf(coordinatesLatitudeList.get(i)));
parseGeoPoint.setLongitude(Double.valueOf(coordinatesLongitudeList.get(i)));
alert.setBusnumber(Integer.valueOf(busnumberList.get(i)));
alert.setDescription(descriptionList.get(i));
alert.setCoordinates(parseGeoPoint);
alert.setCreatedAt(new Date(Long.valueOf(dateCreatedAtList.get(i))));
alertsList.add(alert);
}
}
public GoogleMap.onMarkerClickListener geTinfoMarkerClickListener() {
return new GoogleMap.onMarkerClickListener() {
@Override
public Boolean onMarkerClick(Marker marker) {
busnumberTextView.setText(marker.getSnippet());
descriptiontextView.setText(marker.gettitle());
alertTimeTextView.setText(dateCreatedAtList.get(marker.getId()));
marker.showInfoWindow();
return true;
}
};
}
}
我的问题是:我想添加自定义数据以存储在我的标记中,这样当我单击它时,“ alerTimeTextView”将从“
dateCreatedAtList”中获取标记的创建时间?
以上是大佬教程为你收集整理的使标记带有自定义信息,以供单击时使用(Android,Google Maps v2)全部内容,希望文章能够帮你解决使标记带有自定义信息,以供单击时使用(Android,Google Maps v2)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。