在Google地图上显示当前位置的蓝色点标志

14

当我的蓝点图标消失时,我感到困惑。过去我可以显示蓝点图标,但现在它只是在我的当前位置上缩放摄像头而没有蓝点图标。

以下是我的代码:

private void handleNewLocation(Location location) {
    Log.d(TAG, location.toString());
    double currentLatitude = location.getLatitude();
    double currentLongitude = location.getLongitude();
    LatLng latLng = new LatLng(currentLatitude, currentLongitude);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 21));
  }

输入图像描述


你可能需要在位置更改时更新标记... 在这里查看有关标记的文档(https://developers.google.com/maps/documentation/android/marker)。 - Mikel
1
你需要点击“MyLocation”按钮才能显示蓝点。你可以通过调用“mMap.setMyLocationEnabled(true);”来启用它,尽管从你的截图中看起来你已经启用了它。 - Daniel Nugent
4个回答

42

您需要按照以下步骤进行:

GoogleMap myMap;
myMap.setMyLocationEnabled(true);

你可以在我的 Github 这里获取所有示例项目的代码,并自己尝试:)


这对你有帮助吗?如果是,请接受,谢谢。 - bjiang
这个图标的大小可以增加吗? - Sethuraman Srinivasan

0
在最新的Flutter 2.0.1和Dart 2.12.0中,使用以下更新的方法来显示您当前位置上的蓝点:
myLocationEnabled: true,

0
在 Kotlin 中:
        map.isMyLocationEnabled = true

不要混淆:

map.uiSettings.isMyLocationButtonEnabled = true

我在项目中使用了it。这是结果:

show location with direction google map kotlin android

如需嵌入式视图,请查看第35页,此处


-3

请写下以下内容 -

            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myLoc, 15));

最大缩放视图可达20。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接