【发布时间】:2020-04-09 16:59:26
【问题描述】:
我已经更新了我的问题,请查看它 我正在android中开发Blood Donar应用程序。我正在使用Google Map在地图上显示供体。要在地图上显示多个标记,我正在尝试此代码,但它会使应用程序崩溃
public class Profiles {
String name;
String email;
String latitude;
String longitude;
int type;
public Profiles() { }
public Profiles(String name, String email, String latitude, String longitude , int type) {
this.name = name;
this.email = email;
this.latitude = latitude;
this.longitude = longitude;
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getLatitude() {
return latitude;
}
public void setLatitude(String latitude) {
this.latitude = latitude;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
并且在 MapsActivity 中我得到它喜欢
private void fun() {
databaseReference = FirebaseDatabase.getInstance().getReference().child(Constants.content).child(Constants.profiles).child("lRSFuI5pvBZh1VZQWHI4ev52gXF2");
databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot parent : dataSnapshot.getChildren()) {
Profiles profiles = parent.getValue(Profiles.class);
name = profiles.getName();
String email = profiles.getEmail();
lat = Double.valueOf(profiles.getLatitude());
lon = Double.valueOf(profiles.getLongitude());
type = profiles.getType();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (type == 1) {
marker = new MarkerOptions().position(new LatLng(lat, lon)).title(name);
} else {
marker = new MarkerOptions().position(new LatLng(lat, lon)).title(name)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_bloodbank));
}
mMap.setOnCameraIdleListener(onCameraIdleListener);
mMap.addMarker(marker);
}
我收到此错误
如果我在任何其他活动中获得所有详细信息,它会为我提供一切而不会崩溃,但是当我尝试在 Maps Activity 中使用它时,它会直接导致应用程序崩溃并给出此错误。我可以理解为什么它在我获取其他详细信息时崩溃我尝试过的活动以测试并完美地融入 toast 和 logcat。
【问题讨论】:
-
您可以简单地创建不同的标记对象并将它们添加到应用程序中。您可以自定义每个对象的图标、位置(LatLng)以及标题。
-
我已经更新了我的问题,请您再检查一遍。
-
错误字面上表示您用于 lat-long 的
double值无效。
标签: android google-maps google-maps-markers google-maps-api-2