[英]How to animate the camera to a specified location in Google Maps v2 for Android?
[英]Google Maps animate camera doesn't center on location specified
我有一個非常奇怪的問題,我在任何地方都找不到答案。
目標:
當我將模型加載到地圖上時,我會從該模型中提取一個點,而該點就是我要設置為相機的新中心的點。
問題:
當我使用map.animateCamera(position)
,相機移動到模型下方。 我無法推斷出什么地方出了問題,我已經搜索了文檔,但沒有找到任何東西。
我如何測試:
為了測試位置是否正確,我在地圖上的位置標記了一個標記,並且該標記位於正確的位置,這意味着相機是問題所在。
我也嘗試過使用不同的方法map.moveCamera()
以及CameraUpdateFactory.newCameraPosition()
等。
碼
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));
}
在我看來
當我第一次加載應用程序時,它會正確加載項目的中心點。 map.animateCamera()
就像一個吊飾。 每次我做為中心點它的作品。 但是,當我將map.animateCamera()
移至其他位置時,則無法再次使用它。
所以在我看來,相機的坐標系被移動了
請嘗試以下方法:
map.animateCamera(CameraUpdateFactory.newLatLngZoom(centerPoint , 15), 2000, new GoogleMap.CancelableCallback() {
@Override
public void onFinish() {
}
@Override
public void onCancel() {
}
});
這將花費一些時間進行動畫處理。 我認為,這里的問題是正在處理的動畫的即時執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.