【问题标题】:How to display current location blue point without setMyLocationEnabled true?如何在没有 setMyLocationEnabled true 的情况下显示当前位置蓝点?
【发布时间】:2018-05-10 11:30:57
【问题描述】:

我正在使用谷歌地图 V2,我需要显示自定义图像按钮单击以获取带有蓝点的当前位置,并且不显示 setMyLocationEnabled 按钮。而且这个方法已经是假的了,但是显示当前位置但是不显示蓝点。

  googleMap.setMyLocationEnabled(false);

【问题讨论】:

  • 您是否在 AndroidManifest 文件中添加了权限?
  • 是的..我添加了!!

标签: android google-maps-api-2 android-gps currentlocation


【解决方案1】:

获取有关当前位置的完整信息Read this

添加此权限

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

编码愉快!!

【讨论】:

  • @NajibPuthawala 你在上面添加了权限吗?
  • 但在您的屏幕截图中出现了蓝点。
  • 是的...我在清单和屏幕截图中添加了权限,只需要蓝点...没有我的位置按钮。
  • 您是在真机上测试应用吗?
  • 是的...我测试了设备 Nexus 5 Google。它不会只显示蓝点作为当前位置点。
【解决方案2】:

好吧,我猜您使用 GPS 获得了当前的纬度和经度。之后真的很简单。您制作一个标记对象并将其添加到地图中,如下所示。

MarkerOptions yourMakerOptions;
Marker yourMarker;


    yourMakerOptions = new MarkerOptions();
    yourMakerOptions.title("Title");
    yourMakerOptions.snippet("");
    yourMarkerOptions.position(new LatLng(currentLatitude,currentLongitude));
    //Set your marker icon using this method.
    yourMakerOptions.icon();

最后将其添加到地图中。

yourMarker = map.addMarker(yourMakerOptions);

要将地图移动到当前位置,请在按钮的 onClickListener 中调用此方法。

map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentLatitude, currentLongitude), 14));

希望这会有所帮助。

试试这个:

map.setMyLocationEnabled(true);
map.getUiSettings().setMyLocationButtonEnabled(false);

【讨论】:

  • 好的。但它没有显示蓝点,只添加标记。另一种解决方案?
  • 是的......完美......这个代码......非常感谢...... map.setMyLocationEnabled(true); map.getUiSettings().setMyLocationButtonEnabled(false);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-13
  • 1970-01-01
相关资源
最近更新 更多