繁体   English   中英

Google地图标记仅显示图标

[英]Google maps marker show only icon

我想在Google地图上显示标记(Android)

我使用了以下代码(例如在android开发人员的示例中):

位置,名称和说明有效(我通过调试模式检查了它们)

它向我显示了所需位置的图标,但是没有标记或说明和代码片段。 下一行

mMap.addMarker(MarkerOptions().position(location)
    .title(poi.getName()).snippet(poi.getDescription())
    .icon(BitmapDescriptorFactory.fromBitmap(image_item));

仅显示图标,没有标题或摘要。

非常感谢

您是否遵循文档中的示例? 另外, 示例代码是否与Google Play服务SDK捆绑在一起?

编辑 :您可以通过在目标标记上调用showInfoWindow()来以编程方式显示信息窗口:

Marker marker = mMap.addMarker(new MarkerOptions()
                      .position(location)
                      .title(poi.getName())
                      .snippet(poi.getDescription())
                      .icon(BitmapDescriptorFactory.fromBitmap(image_item));
marker.showInfoWindow();

但是,请记住,一次只能显示一个信息窗口。 如果用户单击另一个标记,则当前窗口将被隐藏,并且将显示新的信息窗口。

试试这个代码。 此代码适用于使用API​​ V2的Google地图。添加google的内置方法。

public void onMapLongClick(LatLng point){

    // Getting the Latitude and Longitude of the touched location
    latLng = point;
    // Clears the previously touched position
    myMap.clear();
    // Animating to the touched position
    myMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
    // Creating a marker
    markerOptions = new MarkerOptions();
    // Setting the position for the marker
    markerOptions.position(latLng);
    // Adding Marker on the touched location with address

    new ReverseGeocodingTask(getBaseContext()).execute(latLng);
    tmpLatLng = latLng;
    drawCircle(point);
    btLocInfo.setEnabled(true);
}

这不是一个罕见的问题,修复它的唯一方法是重新安装它唯一能够修复它的方法。

显示没有标题或摘要的图标。 使用以下代码

LatLng newYork = new LatLng(40.7142, 74.0064);
Marker melbourne = map.addMarker(new MarkerOptions()
                    .position(newYork));

编辑:

显示带有标题和摘要和图标的标记

map.addMarker(new MarkerOptions().position(new LatLng(lat, lon))
                .title(string).snippet(string2).icon(BitmapDescriptorFactory.fromBitmap(image_item));

暂无
暂无

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

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