同一坐标中的许多标记的解决方案,Google Map mashup

时间:2010-01-27 23:47:06

标签: google-maps maps visualization

我正在制作一个混搭,其缩略图将显示在谷歌地图上。

问题是许多缩略图将共享相同的坐标。因此,如果我将它们绘制成标记,那么它们就会成为另一个。

您是否看到过针对此问题的创意解决方案?感谢

5 个答案:

答案 0 :(得分:9)

聚类肯定是有用的,但它没有解决原始问题 - 如果它们共享相同的精确坐标,则显示标记。 Google Maps API v3根本不会这样做。它只显示其中一个。

@RedBlueThing建议的群集解决方案没有解决这个问题。

有几种选择。一个是由@Bryan建议的 - 手动进行一些预处理,并在信息窗口中为最后一个标记放置描述性信息。

或者 - 我更喜欢 - 是将标记预处理到稍微(10m左右),改变那些共享相同位置的坐标。如果你有能力放弃那种精确度。在这里查看一个这样的解决方案http://techxplorer.com/2010/02/05/managing-markers-with-the-same-coordinates-in-a-google-map/。我进一步修改了代码 - 请参阅此处https://gist.github.com/873142

答案 1 :(得分:3)

您需要查找“群集”一词。您基本上只显示一个标记,表明该位置实际上有多个标记。然后在适当的缩放级别,标记开始单独出现。

如果它们位于完全相同的坐标并且永远不会发散,那么当您将鼠标悬停在聚簇标记上时,您将需要实现在屏幕上弹出的内容(如包含缩略图列表的浮动DIV)选择/查看的人,甚至可以右键单击群集并选择单个项目的上下文菜单

答案 2 :(得分:3)

有一些Javascript库可以实现群集,并且很容易集成到现有的mashup中:

  • MarkerClusterer - 我used这是一个mashup,发现很容易集成,有一组很好的默认图标。
  • ClusterMarker - 我没有使用过这个,但看起来非常实用。

您还可以阅读本blog post,其中包含各种备选方案。

答案 3 :(得分:0)

使用群集.make标记组作为cluster.one群集将在其中显示许多标记。

答案 4 :(得分:0)

我有一个优雅而美丽的解决方案:

@Override
public boolean onClusterClick(Cluster<ProfileCardDTO> cluster)
{
    if (inProcessOfClick.size() > 0)
    {
        changeRenderMarkerType(doctorMarkerRenderer.getMarkerType());
        for (Polyline line : polylines)
        {
            line.remove();
        }
        polylines.clear();
    }
    boolean same = true;
    ProfileCardDTO tmpProfile = null;
    for (ProfileCardDTO profile : cluster.getItems())
    {
        if (tmpProfile != null)
        {
            if ((Math.abs(Float.parseFloat(tmpProfile.getPractice().getLatitude()) - Float
                    .parseFloat(profile
                            .getPractice()
                            .getLatitude())) > 0.00001f) || (Math.abs(Float.parseFloat(tmpProfile
                    .getPractice().getLongitude()) - Float.parseFloat(profile
                    .getPractice()
                    .getLongitude())) > 0.00001f))
            {
                same = false;
                break;
            }
        }
        tmpProfile = profile;
    }
    if (zoomLevel >= 12 && same)
    {
        inProcessOfClick.clear();
        int count = cluster.getSize();
        double a = 360.0 / count;
        double radius = 0.0006;
        if (zoomLevel < 17.7)
        {
            radius = 0.0005;
        } else if (zoomLevel < 18.7)
        {
            radius = 0.0003;
        } else if (zoomLevel < 19.7)
        {
            radius = 0.00015;
        } else if (zoomLevel <= 20.7)
        {
            radius = 0.00007;
        } else if (zoomLevel > 20.7)
        {
            radius = 0.00005;
        }
        int i = 0;
        final long duration = 500;
        final long start = SystemClock.uptimeMillis();
        final Interpolator interpolator = new LinearInterpolator();
        for (ProfileCardDTO profile : cluster.getItems())
        {
            MarkerOptions mrk = new MarkerOptions();
            double x = radius * Math.cos((a * i) / 180 * Math.PI);
            double y = radius * Math.sin((a * i) / 180 * Math.PI);
            LatLng latLngEnd = new LatLng(profile.getPosition().latitude + x, profile
                    .getPosition().longitude + y);
            LatLng latLngStart = profile.getPosition();
            mrk.position(latLngStart);
            doctorMarkerRenderer.onBeforeClusterItemRendered(profile, mrk);
            Marker tmpMrk = clusterManager.getMarkerCollection().addMarker(mrk);
            Handler handler = new Handler();
            handler.post(new Runnable()
            {
                @Override
                public void run()
                {
                    long elapsed = SystemClock.uptimeMillis() - start;
                    if (elapsed > duration)
                        elapsed = duration;
                    float t = interpolator.getInterpolation((float) elapsed / duration);
                    double lng = t * latLngEnd.longitude + (1 - t) * latLngStart.longitude;
                    double lat = t * latLngEnd.latitude + (1 - t) * latLngStart.latitude;
                    tmpMrk.setPosition(new LatLng(lat, lng));
                    if (t < 1.0)
                    {
                        handler.postDelayed(this, 10);
                    } else
                    {
                        PolylineOptions line =
                                new PolylineOptions().add(cluster.getPosition(),
                                        cluster.getPosition(),
                                        latLngEnd,
                                        latLngEnd)
                                        .width(5).color(Color.BLACK);
                        polylines.add(getGoogleMap().addPolyline(line));
                    }
                }
            });
            doctorMarkerRenderer.getmMarkerCache().put(profile, tmpMrk);
            clusterManager.addItem(profile);
            inProcessOfClick.add(profile);
            i++;
        }
        tmpCluster = cluster;
        bringMarkerToTop(selectedDoctorMiniProfile);
        new Handler().postDelayed(() ->
        {
            if (doctorMarkerRenderer.getMarker(cluster) != null)
                doctorMarkerRenderer.getMarker(cluster).setAlpha(0.5f);
        }, 250);
    } else
    {
        LatLngBounds.Builder builder = new LatLngBounds.Builder();
        for (ProfileCardDTO profile : cluster.getItems())
        {
            Practice2 location = profile.getLocation();
            LatLng latLng = new LatLng(Double.parseDouble(location.getLatitude()), Double.parseDouble(location
                    .getLongitude()));
            builder.include(latLng);
        }
        LatLngBounds latLngBounds = builder.build();
        CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(latLngBounds, getResources().getDimensionPixelSize(R.dimen.map_padding));
        getGoogleMap().animateCamera(cameraUpdate, ANIMATE_DURATION_MS, new GoogleMap.CancelableCallback()
        {
            @Override
            public void onFinish()
            {
                changeRenderMarkerType(doctorMarkerRenderer.getMarkerType());
            }

            @Override
            public void onCancel()
            {
            }
        });
    }
    return true;
}

片段的完整代码: https://github.com/master255/MapFragment