【问题标题】:Create a Marker without adding it to the map? [closed]创建标记而不将其添加到地图? [关闭]
【发布时间】:2013-05-10 11:37:17
【问题描述】:
  • 如何创建 Marker 类的实例,但不将其添加到地图中。

【问题讨论】:

  • 这对于我正在创建的应用程序来说不仅是至关重要的。

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


【解决方案1】:

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

在您调用 setVisible(true) 之前,它不会实际创建标记。

【讨论】:

  • 它成功了。谢谢。
【解决方案2】:

您可以通过将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())));

希望对你有帮助

【讨论】:

  • 这是选项之一,但实际上仍将标记添加到地图中。我想知道是否有一种方法可以在不添加它的情况下创建它——比如 Flex Maps API。
  • 我认为这只能通过使用com.google.android.gms.internal.z 创建一个新的Marker 对象来完成,例如Marker m = new Marker(new z()/* with complete anonymous inner class*/)
  • @AnujMathur_07 Marker 构造函数不应该对开发人员可用,并且尝试使用它并不好。见this gmaps issue。
  • 我没有意识到 addMarker() 返回了标记对象,所以这个小花絮将我带到了我不知道的下一件事上。谢谢。
猜你喜欢
  • 2018-10-11
  • 2014-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多