gpt4 book ai didi

java - 谷歌地图标记标题显示的是完整列表

转载 作者:行者123 更新时间:2023-12-02 09:03:59 25 4
gpt4 key购买 nike

我现在正在使用谷歌地图项目,我从 firebase 获取我的数据,我能够在本网站所有开发人员的帮助下绘制多个标记,一件事是在绘制这些标记时我的标记标题是相同的, “相同”意味着我所有的标记都有相同的标题请查看我的图片 enter image description here

enter image description here

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

private GoogleMap mMap;
private GoogleMap googleMap;
private MarkerOptions options = new MarkerOptions();
private ArrayList<LatLng> latlngs = new ArrayList<>();
private ArrayList<String> Names = new ArrayList<>();
String Lat ,Lon,Names1;
double latitude , longitude;







@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);





FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("Positions");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

for (DataSnapshot chidSnap : dataSnapshot.getChildren()) {

// System.out.println(chidSnap.getKey()); //displays the key for the node
// System.out.println(chidSnap.child("Latitude").getValue());
// System.out.println( chidSnap.child("Longitude").getValue()); //gives the value for given keyname


//some latitude and logitude value

// System.out.println(latlngs); //gives the value for given keyname

Lat = String.valueOf(chidSnap.child("Latitude").getValue());
Lon = String.valueOf(chidSnap.child("Longitude").getValue());
Names1 = String.valueOf(chidSnap.getKey());

latitude= Double.parseDouble(Lat);
longitude= Double.parseDouble(Lon);
latlngs.add(new LatLng(latitude, longitude));
Names.add(Names1);
}


if(mMap != null) {




for (LatLng point : latlngs) {
options.position(point);
options.title(String.valueOf(Names));
options.snippet("someDesc");
mMap.addMarker(options);
}
}



}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});


// System.out.println(Names);


}









/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {



mMap = googleMap;




for (LatLng point : latlngs) {
options.position(point);
options.title(String.valueOf(Names));
options.snippet("someDesc");
googleMap.addMarker(options);
}


}
}

上面是我的 MapsActivity。我期望的是一个标记应命名为 Lex B05 ,另一用户应命名为 amanda 谢谢提前寻求您的帮助!..

最佳答案

因为您将相同的 arrayList 名称传递给所有标记,所以在添加标记时尝试以下代码

for (int i=0;i< latlngs.size();i++) {
LatLng point=latlngs.get(i);
options.position(point);
options.title(Names.get(i));
options.snippet("someDesc");
mMap.addMarker(options);
}

希望这会有所帮助!!

关于java - 谷歌地图标记标题显示的是完整列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59966735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com