Markers change position with zoom in/out

ⅰ亾dé卋堺 提交于 2020-01-04 06:08:09

问题


I'm using the Google Maps API v2 for Android, and I want to place a couple of markers on the map. I have the code as following

       @Override
       public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

       {
        View rootView = inflater.inflate(R.layout.fragment_map, container, false);

        MapFragment fm = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
        map = fm.getMap();
        rootView.findViewById(R.id.map_hybrid).setSelected(true);


        map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        map.getUiSettings().setCompassEnabled(true);

        CameraPosition cameraPosition = new CameraPosition.Builder()
                                                .target(new LatLng(39.15326,-9.362926))
                                                .zoom(15)
                                                .build();
        MapFragment.newInstance(new GoogleMapOptions()
                        .camera(cameraPosition));

        map.addMarker(new MarkerOptions().position(new LatLng(39.15326,-9.362926))
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.btn_map_home))); 
        while(i < mapInfo.size())
        {
            BitmapDescriptor mapIcon;

            ... changes the resource of the mapIcon accordingly...

            map.addMarker(new MarkerOptions()
                            .draggable(false)
                            .title(((ArrayList<String>) mapInfo.get(i)).get(3))
                            .position(new LatLng(((ArrayList<Double>) mapInfo.get(i)).get(0), ((ArrayList<Double>) mapInfo.get(i)).get(1)))
                            .icon(mapIcon));
            i = i + 1;
        }   

And whenever I zoom in and zoom out, the icons move. I want them to be fixed

EDIT: Images explaining the issue.


回答1:


The most likely problem its the image your using as a marker. You must be really carefull that your custom marker points to the same point that the defaults markers or it will not point to the same point once you zoom out enough.

http://i.stack.imgur.com/QekbY.jpg

if you use something like this:

http://i.stack.imgur.com/nTAtP.png

The most likely result will be a lot of distortion(and it get worse the more you zoom out!)

Hope this helps you!



来源:https://stackoverflow.com/questions/25450055/markers-change-position-with-zoom-in-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!