尝试在Android Studio中将标记添加到Google Maps片段。当代码在android设备上运行时,代码会成功在地图上成功显示标记,但是当尝试在模拟器上运行时,标记永远不会显示
marker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(point.getLat(), point.getLongi()))
.title("Point: " +point.getID())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_CYAN))
);
marker.setSnippet("Latitude: " + point.getLat() + "\nLongitude: " + point.getLongi() + "\nDescription: " + point.getDesc() + "\nLight at " + point.getTime() + " : " + point.getLight());
marker.setTag(point.getID());
markers.add(marker);
marker.setVisible(true);
预期:在地图上显示自己的标记 实际:未显示任何标记
出于某些原因,该标记确实会显示:
mMap.addMarker(new MarkerOptions()
.position(new LatLng(10, 10))
.title("Hello world"));
XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/include"
layout="@layout/content_main" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"/>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="382dp"
map:layout_anchor="@+id/include"
map:layout_anchorGravity="bottom|center"
tools:context=".MapsActivity" />
</android.support.design.widget.CoordinatorLayout>
已修复,将其保留为我的耻辱的证明,标记在地图上,但模拟器设置为N. America。由于我的愚蠢,我没有缩小并看到它,但它始终没有被破坏