简体   繁体   English

将地图动画化为onClick方法中的标记位置

[英]Animate map to marker position in onClick method

I found a strange bug in the googleMap v2. 我在googleMap v2中发现了一个奇怪的错误。 When I try to animateCamrea to a marker position inside of the override Marker onClick method it doesn't work. 当我尝试将Camrea动画化为覆盖Marker onClick方法内部的标记位置时,它不起作用。 Only moveCamera seems to work in this scenario. 在这种情况下,似乎只有moveCamera起作用。 Even when I try to animate camera to a random position it still doesn't work. 即使当我尝试将相机设置为随机位置时,它仍然无法正常工作。

@Override
public boolean onMarkerClick(Marker mmarker) {

    if(mmarker.getSnippet().equals("CITY")){

        map.animateCamera(CameraUpdateFactory.newLatLngZoom(mmarker.getPosition(), (float) 11.20));
        //updateMapMarkers(0);
    }

    return false;
}

This is the default behaviour. 这是默认行为。 Why are you re-defining it? 为什么要重新定义它?

If you return false from onMarkerClick , the Maps API will perform its default behaviour (panning to the marker). 如果您从onMarkerClick返回false ,则Maps API将执行其默认行为(平移到标记)。

You'll want to return true if you are overriding that behaviour or don't want it to happen. 如果您要覆盖该行为或不希望发生这种情况,则需要返回true

Check the documentation for OnMarkerClickListener for more information. 有关更多信息,请OnMarkerClickListener文档

If you only want to animate on a condition like that, then this will be more succinct: 如果只想在这样的条件下进行动画处理,那么这将更加简洁:

@Override
public boolean onMarkerClick(Marker mmarker) {
    return !mmarker.getSnippet().equals("CITY");
}

This will pan the map only when the snippet is "CITY". 仅当摘要为“ CITY”时,此地图才会平移地图。 You may also want to reverse the call to equals() . 您可能还想将调用撤消到equals()

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

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