Android 放大地图并以自定义标记为中心
Android zoom in and center around custom marker in a map
我正在使用 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);
通过 map.setMyLocationEnabled(false)
禁用 myLocation 层后,此侦听器也无法正常工作。
所以您应该通过其他方式接收位置信息。
https://developer.android.com/training/location/receive-location-updates.html
设置正确后,您可以在此回调上绘制标记。
@Override
public void onLocationChanged(Location location) {
...
}
我正在使用 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);
通过 map.setMyLocationEnabled(false)
禁用 myLocation 层后,此侦听器也无法正常工作。
所以您应该通过其他方式接收位置信息。 https://developer.android.com/training/location/receive-location-updates.html
设置正确后,您可以在此回调上绘制标记。
@Override
public void onLocationChanged(Location location) {
...
}