问题描述
我正在创建一个在线混乱应用程序,其中有两次针对混乱所有者的登录,一次针对用户的登录,因此当混乱所有者在其数据中放置位置时,应该在用户端的地图上标记.
I'm creating a online mess application where there are two logins one for mess owner and another for user so when mess owner put location in his data there should be marker on map in user side.
这是图像中的数据库结构数据库结构
here is structure of database in imageDatabase structure
请建议我编写代码以访问那些经度n值,并为每个注册了位置值的烂摊子在地图上创建标记.
please suggest me code to access those latitude n longitude values and create marker on map for each mess registered with location values.
推荐答案
已编辑正在提议对数据库结构进行少量调整...在"MessProviders"下,使用userID,mProviderLatitude,mProviderLongitude,mProviderBrandName创建另一个名为"locations"的节点. .如果您为getter和setter设置了单独的类,那将是很好的.我的课程是"CordinatesModel"
EDITEDAm proposing a small adjustment to the database structure...under 'MessProviders' create another node called 'locations' with the userID,mProviderLatitude,mProviderLongitude, mProviderBrandName. .It would be good if you had a separate class for getters and setters. My class for that is 'CordinatesModel'
private void messLocation() {
DatabaseReference currentDBcordinates = FirebaseDatabase.getInstance().getReference().child("Users").child("MessProviders").child("locations");
currentDBcordinates.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//Create an array of markers
int size = (int) dataSnapshot.getChildrenCount(); //
Marker[] allMarkers = new Marker[size];
mMap.clear(); //Assuming you're using mMap
for(DataSnapshot ds : dataSnapshot.getChildren()) {
//Specify your model class here
CordinatesModel cordinatesModel = new CordinatesModel();
//lets create a loop
for(int i=0;i<=size;i++) {
try {
//assuming you've set your getters and setters in the Model class
cordinatesModel.setmProviderLatitude(s.getValue(CordinatesModel.class).getmProviderLatitude());
cordinatesModel.setmProviderLongitude(s.getValue(CordinatesModel.class).getmProviderLongitude());
cordinatesModel.setmProviderBrandName(s.getValue(CordinatesModel.class).getmProviderBrandName());
//lets retrieve the coordinates and other information
Double latitude1 = cordinatesModel.getmProviderLatitude();
Double longitude1 = cordinatesModel.getmProviderLongitude();
String brandName=cordinatesModel.getmProviderBrandName();
//convert the coordinates to LatLng
LatLng latLng = new LatLng(latitude1, longitude1);
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//Now lets add updated markers
//lets add updated marker
allMarkers[i] = mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)).position(latLng).title(brandName));enter code here
}catch (Exception ex){}
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
这篇关于从Firebase检索位置,然后在Android应用程序的Google Map API上放置标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!