标记不会显示

时间:2018-09-20 03:48:01

标签: android google-maps firebase marker

我尝试在与Firebase同步的Google地图上放置标记,而我对此没有任何问题。问题是我的标记不会显示在mapFragment上。...我认为这里存在错误:

div p {...}

这是我的代码

mMap.addMarker(new MarkerOptions()
                        .position(location)
                        .title(user.name).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

xml代码:(请不要判断我的代码混乱,我是新来的……)

public class ChooseGoogleMaps extends FragmentActivity implements 
OnMapReadyCallback,LocationListener,GoogleMap.OnMarkerClickListener{
private GoogleMap mMap;
private ChildEventListener mChildEventListener;
private DatabaseReference mUsers;
Marker marker;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_choose_google_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to 
be used.
    SupportMapFragment mapFragment = (SupportMapFragment) 
getSupportFragmentManager()
            .findFragmentById(R.id.otherMap);
    mapFragment.getMapAsync(this);
    ChildEventListener mChildEventListener;
    mUsers= FirebaseDatabase.getInstance().getReference("Users");
    mUsers.push().setValue(marker);

}


@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    googleMap.setOnMarkerClickListener(this);
    googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    mUsers.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot s : dataSnapshot.getChildren()){
                UserInformation user = s.getValue(UserInformation.class);
                assert user != null;
                LatLng location=new LatLng(user.latitude,user.longitude);
                mMap.addMarker(new MarkerOptions()
                        .position(location)
                        .title(user.name).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

            }
        }

<?xml version="1.0" encoding="utf-8"?>

这是日志:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/indo_launcherr"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/indo_launcherr"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".home">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MapsActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Login.Login">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Genre">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".All_Area" />
    <activity android:name=".Choose_Area" />
    <activity android:name=".Near_Me" />
    <activity android:name=".Popular" />
    <activity android:name=".Bookmarked" />
    <activity android:name=".Login.PasswordActivity" />
    <activity android:name=".Login.ProfileActivity" />
    <activity android:name=".Login.RegistrationActivity" />
    <activity android:name=".Login.UpdatePassword" />
    <activity android:name=".Login.UpdateProfile" />
    <activity
        android:name=".DetailActivity"
        android:parentActivityName=".home" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

    <uses-library
    android:name="org.apache.http.legacy"
    android:required="false" />

    <activity android:name=".SplashScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
    <activity
        android:name=".ChooseGoogleMaps"
        android:label="@string/title_activity_choose_google_maps" />

</application>

1 个答案:

答案 0 :(得分:0)

请检查以下内容

1-您的清单中有Internet访问权限和Internet权限

2-通过在数据更改的内部添加“日志”以指定错误来正确接收用户的数据

3-如果您的日志中有任何印刷内容,请向我们展示,还可以预览您的XML代码,以防万一

注意:此代码将继续添加标记,这些标记不会更新