简体   繁体   中英

Google Maps animate camera doesn't center on location specified

I am having a very curious issue and i couldn't find the answers anywhere.

Goal:
When i load a model onto a map i extract a point from that model and that point is what i want to set as the new center of camera.

The problem:
When i use map.animateCamera(position) the camera moves below the model. I cannot deduce what is wrong and I've searched through the documentation but didn't find anything.

How i tested:
To test out if the location was correct, i placed a marker on the map where the point is, and that marker is in the correct place, that means that camera is the problem.

I've tried also with different methods map.moveCamera() as well as CameraUpdateFactory.newCameraPosition() , etc...

Code

private void recenterModel(List<PolygonOptions> t) {
    if(t == null || t.isEmpty()) return;
    int center = t.size()/2;
    PolygonOptions polygon = t.get(center);
    while(polygon.getPoints().isEmpty()){
        polygon = t.get((++center%t.size()));
        if(center > t.size()+1) return; /*If we are here, there aren't any points in model*/
    }
    center = polygon.getPoints().size()/2;
    LatLng centerPoint = polygon.getPoints().get(center);

    GoogleMap map = modelMapDrawable.ctx.getMap();
    map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerPoint , 15));
    map.addMarker(new MarkerOptions().position(centerPoint)); 
}

What it seems to me
When i firstly load the app, it loads project's center point correctly. map.animateCamera() works like a charm. Every time i do it for the center point it works. BUT when i do map.animateCamera() to other location, then i cannot get it to work again.
So it seems to me like the camera's coordinate system gets moved

Please try this:

map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerPoint , 15), 2000, new GoogleMap.CancelableCallback() {
    @Override
    public void onFinish() {

    }

    @Override
    public void onCancel() {

    }
});

This will give some time to animate. I think, the problem here, is with the instant execution of the animation being processed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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