首页 > 解决方案 > 谷歌地图标记显示在安卓设备上,但不在模拟器上

问题描述

尝试在 android studio 中向谷歌地图片段添加标记。当代码在 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。在我的愚蠢中,我没有缩小并看到这个,它从一开始就没有被打破

标签: javaandroidgoogle-mapsandroid-layout

解决方案


推荐阅读