谷歌地图没有显示标记android

时间:2016-08-30 10:31:32

标签: android maps zoom marker

所以,我尝试实现自己的Google Maps Activity版本,但无济于事。我遇到了一个问题,我的标记没有出现,经过几个小时没有搞清楚,我删除了我的代码并复制了这些人的工作示例。除了,当我运行它时,它是同样的问题。地图不会缩放到指定位置,也不会显示地图标记。这让我相信onReady部分存在问题,但我不确定。我已经尝试过其他堆栈问题/答案,但我似乎无法找出问题所在。它会显示谷歌地图,我可以手动放大它,它会更新街道和诸如此类的东西,但没有标记。

Pastebin Link to Java Code

XML文件:
<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="match_parent" tools:context="com.test.logintest.MapsActivity" />

2 个答案:

答案 0 :(得分:1)

尝试在onMapReady()方法中添加您的markeroptions代码。当位置发生变化时(onLocationChanged()),它可能会在当前添加标记时起作用。

LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
    MarkerOptions markerOptions = new MarkerOptions();
    markerOptions.position(latLng);
    markerOptions.title("Current Position");
    markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA));
    mCurrLocationMarker = mGoogleMap.addMarker(markerOptions);

答案 1 :(得分:0)

发现了这个问题。这实际上是我的其他Java文件中的一个错误。我试图切换活动,但实际上没有切换活动,我只改变了视图。