简体   繁体   中英

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.
  • 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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