标记通过放大/缩小改变位置 [英] Markers change position with zoom in/out

查看:59
本文介绍了标记通过放大/缩小改变位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android专用的Google Maps API v2,我想在地图上放置几个标记.我有以下代码

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

图片说明了问题. >

Images explaining the issue.

推荐答案

最有可能的问题是您用作标记的图像. 您必须非常小心,以使自定义标记指向默认标记的同一点,否则,一旦足够缩小,它就不会指向同一点.

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!)

希望这对您有所帮助!

这篇关于标记通过放大/缩小改变位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆