android google map marker placing

痞子三分冷 提交于 2019-12-04 03:52:49

The logic behind how the markers are anchored is something like this:

0,0 0.5,0.0 1,0 *-----+-----+-----+-----* | | | | | | | | | | 0,0.5 +-----+-----+-----+-----+ 1,0.5 | | | X | | (U, V) = (0.7, 0.6) | | | | | *-----+-----+-----+-----* 0,1 0.5,1.0 1,1

Also take into consideration that based on your bitmap resource, it could be positioned a little different than you would expect, because they actually approximate to the nearest snap position. So in the example above, your anchor points will snap to this position: *-----+-----+-----+-----* | | | | | | | | | | +-----+-----+-----X-----+ (X, Y) = (3, 1) | | | | | | | | | | *-----+-----+-----+-----*

Use MarkerOption's anchor method: https://developers.google.com/android/reference/com/google/android/gms/maps/model/MarkerOptions.html#anchor(float,%20float)

For your case:

MarkerOptions marker = new MarkerOptions()
.anchor(0.5f, 1.0f)
// Rest of the properties follow

Try this one:

googleMap.addMarker(new MarkerOptions().position(
                new LatLng(51.507351, -0.127758)).icon(
                BitmapDescriptorFactory.fromBitmap(BitmapFactory
                        .decodeResource(getResources(),
                                R.drawable.q_icon))).anchor(0.5f, 1f));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(
    new LatLng(51.507351, -0.127758), 20));

Try this,

private GoogleMap mMap;

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

mMap.addMarker(new MarkerOptions()
    .position(new LatLng(0, 0))
    .title("Hello world")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!