简体   繁体   English

android-maps-extensions infoWindow不显示

[英]android-maps-extensions infoWindow doesn't show

I need display >100 markers on the map and show info window after click on marker. 我需要在地图上显示> 100个标记,然后单击标记后显示信息窗口。 I have used android google maps api v2, but it is lagging with such number of markers. 我已经使用了android google maps api v2,但是它与这种数量的标记滞后。 So I decided switch to android-maps-extensions. 所以我决定切换到android-maps-extensions。 After I did it info window has stopped appear after click on marker. 完成操作后,单击标记后,信息窗口将停止显示。

Here is my code: 这是我的代码:

private void prepareMap() {
    SupportMapFragment fragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.locationsMap);
    map = fragment.getExtendedMap();

    ClusteringSettings settings = new ClusteringSettings();
    settings.clusterOptionsProvider(new ClusterOptionsProvider() {
        @Override
        public ClusterOptions getClusterOptions(List<Marker> markers) {
            float hue = BitmapDescriptorFactory.HUE_RED;
            BitmapDescriptor icon = BitmapDescriptorFactory.defaultMarker(hue);
            return new ClusterOptions().icon(icon);
        }
    });
    settings.clusterSize(100);
    settings.addMarkersDynamically(true);
    map.setClustering(settings);

    map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            // breakpoint here are working. marker is not null
            marker.showInfoWindow();
            return false;
        }
    });
}

public void onLoadFinished(android.support.v4.content.Loader loader, Cursor cursor) {
    if (map != null) {
        cursor.moveToFirst();
        int count = cursor.getCount();
        for (int i = 0; i < count; i++) {

            Location location = new Location(cursor);

            MarkerOptions options = new MarkerOptions();
            options.position( new LatLng(location.getLatitude(), location.getLongitude()));
            options.title(location.getTitle()); // title is not null
            options.snippet(location.getAddress()); // address is not null
            options.data(location);
            map.addMarker(options);
            cursor.moveToNext();
        }
    }
}

Any suggestions? 有什么建议么? I have try use own InfoWindowAdapter, but it is not scaling this window for appropriate content, however I am using wrap_content attribute in xml. 我尝试使用自己的InfoWindowAdapter,但是它没有为适当的内容缩放此窗口,但是我在xml中使用wrap_content属性。

As there is no support for setting title on ClusterOptions (yet), you will have to use InfoWindowAdapter (you may put a separate question on why it is not working as you want it) or add title to ClusterOptions yourself and make sure its value is forwarded to virtual marker that represents cluster. 由于尚不支持在ClusterOptions上设置标题(尚未),因此您将不得不使用InfoWindowAdapter (您可能会提出一个单独的问题,说明为什么它不能按您的意愿工作)或自己为ClusterOptions添加title并确保其值为转发到代表群集的virtual标记。 This sounds complicated but is fairly easy. 这听起来很复杂,但相当容易。 You may also want to add issue on GitHub regarding title not being supported for clustrers. 您可能还想在GitHub上添加有关群集不支持标题的问题。
After that you may use something like: 之后,您可以使用类似:

return new ClusterOptions().icon(icon).title("Test");

Then you will have to figure out what title will best fit your needs. 然后,您将必须找出最适合您需求的标题。 You will most likely want to use List<Marker> to calculate title for this group of markers. 您很可能希望使用List<Marker>来为这组标记计算标题。

Note: If you zoom enough to show separate markers, you can click on them to show title. 注意:如果缩放到足以显示单独的标记,则可以单击它们以显示标题。 If not, there is something more wrong in your code. 如果不是,则您的代码中存在更多错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM