创建标记而不将其添加到地图中?

时间:2013-05-10 11:37:17

标签: android google-maps-android-api-2

  • 如何创建Marker类的实例,但不将其添加到地图中。

2 个答案:

答案 0 :(得分:4)

您可以将visibility设置为false

来执行此操作
Marker marker = mMap.addMarker(new MarkerOptions()
                            .position(
                                    new LatLng(arg0.latitude,
                                            arg0.longitude))
                            .draggable(true).visible(false));

修改

Marker m = new Marker(new z() {

                @Override
                public IBinder asBinder() {
                    return null;
                }

                @Override
                public void showInfoWindow() throws RemoteException {

                }

                @Override
                public void setVisible(boolean paramBoolean)
                        throws RemoteException {

                }

                @Override
                public void setTitle(String paramString)
                        throws RemoteException {

                }

                @Override
                public void setSnippet(String paramString)
                        throws RemoteException {

                }

                @Override
                public void setPosition(LatLng paramLatLng)
                        throws RemoteException {

                }

                @Override
                public void setDraggable(boolean paramBoolean)
                        throws RemoteException {

                }

                @Override
                public void remove() throws RemoteException {

                }

                @Override
                public boolean isVisible() throws RemoteException {
                    return false;
                }

                @Override
                public boolean isInfoWindowShown() throws RemoteException {
                    return false;
                }

                @Override
                public boolean isDraggable() throws RemoteException {
                    return false;
                }

                @Override
                public void hideInfoWindow() throws RemoteException {

                }

                @Override
                public int hashCodeRemote() throws RemoteException {
                    return 0;
                }

                @Override
                public String getTitle() throws RemoteException {
                    return null;
                }

                @Override
                public String getSnippet() throws RemoteException {
                    return null;
                }

                @Override
                public LatLng getPosition() throws RemoteException {
                    return null;
                }

                @Override
                public String getId() throws RemoteException {
                    return null;
                }

                @Override
                public boolean g(z paramz) throws RemoteException {
                    return false;
                }
            });

然后在你想要的时候添加它

mMap.addMarker(new MarkerOptions().position((m.getPosition())));

希望有所帮助

答案 1 :(得分:4)

您可以使用LazyMarker.java中的Android Maps Extensions

在您呼叫setVisible(true)之前,它不会物理创建标记。