简体   繁体   English

自定义地图标记会在android中放大或缩小地图时更改其位置

[英]Custom map marker change its postition when zoom in or out the map in android

I have made a custom marker,it comes perfectly when map is loaded,but my problem is when i zoom in or out the map,marker changes its position and also when i click on marker info window comes on another postition(not on its top),My code is as below,I cant find solution or idea what i have made wrong,Please save me. 我做了一个自定义标记,当加载地图时,它很完美,但是我的问题是当我放大或缩小地图时,标记会更改其位置,并且当我单击标记信息窗口时,它会出现在另一个位置(不在其顶部) ),我的代码如下,我找不到解决方法或想法我做错了什么,请救救我。 code

private void plotMarkers(ArrayList<MyMarker> markers) {
    if (markers.size() > 0) {
        for (MyMarker myMarker : markers) {
            System.out.println("================rounded bitmaps==========="
                    + roundedBitmaps.toString());
            // Create user marker with custom icon and other options
            MarkerOptions markerOption = new MarkerOptions()
                    .position(new LatLng(myMarker.getmLatitude(), myMarker
                            .getmLongitude()));

            markerOption.icon(BitmapDescriptorFactory.fromBitmap(myMarker
                    .getImgURL()));

            CameraPosition cameraPosition = new CameraPosition.Builder()
                    .target(new LatLng(myMarker.getmLatitude(), myMarker
                            .getmLongitude())).zoom(12).build();

            mMap.animateCamera(CameraUpdateFactory
                    .newCameraPosition(cameraPosition));

            Marker currentMarker = mMap.addMarker(markerOption);

            mMarkersHashMap.put(currentMarker, myMarker);

            mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
        }
    }
}

Custom Markers work in a different way as the standard markers. 自定义标记的工作方式与标准标记不同。 The problem you are facing is a known issue, The best way to deal with this are as follows: 您面临的问题是一个已知问题,解决此问题的最佳方法如下:

  • Make sure that the image for the custom marker is symmetrical and id perfectly aligned to the anchor. 确保自定义标记的图像对称且ID与锚完美对齐。
  • The info window should also be similarly aligned symmetrically in the center of the marker, else it will look ugly. 信息窗口也应类似地在标记的中心对称对齐,否则看起来很难看。 Please note that the Custom marker icons often require a different anchor . 请注意,自定义标记图标通常需要使用不同的锚点 For the info window, use a custom info window layout (with a custom background) to align it correctly to the marker. 对于信息窗口,请使用自定义信息窗口布局(具有自定义背景)将其正确对准标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM