Create a Marker without adding it to the map? [closed]

非 Y 不嫁゛ 提交于 2019-12-13 12:58:47

问题


  • How to create instance of Marker class, but without adding it to the map.

回答1:


You may use LazyMarker.java from Android Maps Extensions.

It doesn't physically create marker until you call setVisible(true) on it.




回答2:


You can do this by setting the visibility to false

Marker marker = mMap.addMarker(new MarkerOptions()
                            .position(
                                    new LatLng(arg0.latitude,
                                            arg0.longitude))
                            .draggable(true).visible(false));

Edit

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;
                }
            });

And then adding it when you want like this

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

Hope it helps



来源:https://stackoverflow.com/questions/16481359/create-a-marker-without-adding-it-to-the-map

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