标记不会显示



我尝试在与Firebase同步的Google地图上放置标记,但我没有问题。 问题是我的标记不会出现在地图片段上....我认为这里有一个错误:

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

所以这是我的代码

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代码:(请不要判断我混乱的代码,我是新手...

<?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>

这是日志:

13:15   Emulator: 
13:15   Emulator: This application has requested the Runtime to terminate it 
in an unusual way.
13:15   Emulator: Please contact the application's support team for more 
information.
13:15   Gradle build finished with 1 error(s) in 30s 304ms
13:16   Emulator: Process finished with exit code 255
13:16   Executing tasks: [:app:assembleDebug]
13:16   Gradle build finished with 1 error(s) in 16s 836ms
13:18   Emulator: ANGLE: egl::`anonymous- 
namespace'::CreateDisplayFromAttribs: make D3D display
13:18   Emulator: ANGLE: D3D11: rx::Renderer11::generateConfigs
13:18   Emulator: Process finished with exit code 0
13:21   Executing tasks: [:app:assembleDebug]
13:22   Gradle build finished with 1 error(s) in 1m 0s 160ms

请检查以下内容

1-您在清单中具有互联网访问权限和互联网权限

2-通过在数据更改时添加"日志"来指定错误,从而正确接收用户的数据

3-如果您的日志中打印了任何内容,请向我们出示,并预览您的XML代码以防万一

注意:此代码将继续添加不更新的标记

相关内容

  • 没有找到相关文章

最新更新