我正在使用Google地图API V2。我已经禁用了map.isMyLocationEnabled(),因此我使用自己的自定义图标代替蓝点。由于我的位置图层已禁用,因此地图不会放大我的图标周围。有人能指出我该怎么做吗?
GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() {
@Override
public void onMyLocationChange (Location location) {
LatLng loc = new LatLng (location.getLatitude(), location.getLongitude());
if (marker != null) {
marker.remove(); // remove the old marker
}
marker = map.addMarker(new MarkerOptions()
.position(loc)
.draggable(true)
.title("Not your location? wait 10 few seconds until the icon displays your real location")
.visible(true)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mmyicon))
.flat(true)); // allows it rotate with the earth and change
// perspective as needed and retain it's
// size
map.moveCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 15));
//startIntentService(location);
}
};
map.setOnMyLocationChangeListener(myLocationChangeListener);
答案 0 :(得分:2)
按map.setMyLocationEnabled(false)
禁用myLocation图层后,此侦听器也无法正常工作。
所以你应该通过另一种方式接收位置。 https://developer.android.com/training/location/receive-location-updates.html
设置完所有内容后,您可以在此回调中绘制标记。
@Override
public void onLocationChanged(Location location) {
...
}