【问题标题】:how to focus google marker by marker title?如何通过标记标题聚焦谷歌标记?
【发布时间】:2016-09-20 08:26:47
【问题描述】:

我想通过给出标题来关注标记我现在通过使用 lat 和 lng 来关注

mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(26.89454, 75.82607), 15.0f));

所以无论如何我可以通过标记的标题名称关注特定标记

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    您可以将标记存储在Map<String Marker> 中,使用标题作为键:

    private Map<String, Marker> markers = new HashMap<>();
    

    当您将标记添加到地图时,您还需要将它们添加到哈希图中:

    String markerTitle = "My Marker";
    LatLng markerPosition = new LatLng(26.89454, 75.82607);
    Marker marker = mMap.addMarker(new MarkerOptions().position(markerPosition).title(markerTitle));
    markers.put(markerTitle, marker); // Add the marker to the hashmap using it's title as the key
    

    然后您可以将查询哈希图的标记居中:

    private void centerMarker(String title) {
        Marker marker = markers.get(title);
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(marker.getPosition(), 15f));
    }
    

    【讨论】:

    • 先生,如果我从服务器获取标记名称、经纬度和经纬度,那么您有什么办法吗?
    • 你也可以这样做,你只需要从你的服务器获取数据并从那里设置位置和标题
    • 你能编辑你的问题并在那里添加你的代码,这样更清楚吗?
    猜你喜欢
    • 2013-08-01
    • 2012-12-17
    • 2013-01-08
    • 2014-04-05
    • 1970-01-01
    • 2020-09-26
    • 2013-07-20
    • 2018-03-29
    相关资源
    最近更新 更多