我遇到了如何在Arraylist上添加addMarker的问题。我在for循环中使用createMarker来添加值。
try:
employee = float(raw_input('Employee code number or 0 for guest: ') or 0.0)
except ValueError:
print "Nice try buddy"
print "Welcome BIG_OLD_BUDDY"
问题在于,当调用createMarker时,标记只会替换它在Arraylist上的值。我想要的是在[0,0,0,0]中添加arraylist中的标记..我该如何实现?
self.user = self.pool?.currentUser()
let mfaOptions = AWSCognitoIdentityUserMFAOption()
mfaOptions.attributeName = "email"
mfaOptions.deliveryMedium = AWSCognitoIdentityProviderDeliveryMediumType.email
let settings = AWSCognitoIdentityUserSettings()
settings.mfaOptions?.append(mfaOptions)
self.user!.setUserSettings(settings).continueWith( executor: AWSExecutor.mainThread(), block: { (task: AWSTask!) -> Void in
print(task.debugDescription)
if let error = task.error as NSError? {
print("error")
} else {
print("updated 2 factor")
}
})
答案 0 :(得分:1)
它不会覆盖某个值,而是替换整个列表。
不要制作新的清单。让方法创建并返回。
public MarkerOptions createMarker(Double latitude, final Double longitude, String Plate_num) {
// list = new ArrayList<>(); // Don't do this
BitmapDescriptor image = BitmapDescriptorFactory.fromResource(R.drawable.bus);
return new MarkerOptions()
.position(new LatLng(latitude, longitude))
.title("Plate No.")
.snippet(Plate_num)
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
}
...
onResponse( ... ) {
...
String lng = String.valueOf(longiString);
MarkerOptions opts = createMarker(d, d2, plate_num);
Marker m = mMapFragment.addMarker(opts);
list.add(m);
}