2017-11-27 16 views
0

私はマップを使って作業しています。私のアプリでは、SupportMapFragmentが画面いっぱいになっています。マーカーがクリックされると、ポップアップが表示されます。このポップアップが表示されると、画面の75%を取得します。カメラの地図は決してオフセット位置に移動しません

そのため、残りの25%にマーカーを中央に配置する必要があります。これを行うには、私はCluserManagerからsetOnClusterItemClickListenerを使用しています。しかし、私が何をしても、常にSupportMapFragmentの中心にマーカーが移動します。

How to center the camera so that marker is at the bottom of screen? (Google map api V2 Android)

ません成功:

私はこの回答から、ほとんどのソリューションを試してみました。以下に私はいくつかのコードを書いています。私が知りたいのは、マーカーが画面の中央に移動し続けている理由です。

clusterManager.setOnClusterItemClickListener(new ClusterManager.OnClusterItemClickListener<MyItem>() { 
    @Override 
    public boolean onClusterItemClick(MyItem myItem) { 

    LatLng location = myItem.getPosition(); 


    /*float zoom_lvl = googleMap.getCameraPosition().zoom; 
    double dpPerdegree = 256.0*Math.pow(2, zoom_lvl)/170.0; 
    double screen_height = (double) mapFragment.getView().getHeight(); 
    double screen_height_30p = 50.0*screen_height/100.0; 
    double degree_30p = screen_height_30p/dpPerdegree; 
    LatLng centerlatlng = new LatLng(location.latitude, location.longitude + degree_30p); 
    googleMap.animateCamera(CameraUpdateFactory.newLatLng(centerlatlng), 1000, null);*/ 

    Projection projection = googleMap.getProjection(); 
    LatLng markerPosition = myItem.getPosition(); 
    Point markerPoint = projection.toScreenLocation(markerPosition); 
    Point targetPoint = new Point(markerPoint.x, markerPoint.y - mapFragment.getView().getHeight()/4); 
    LatLng targetPosition = projection.fromScreenLocation(targetPoint); 
    googleMap.animateCamera(CameraUpdateFactory.newLatLng(targetPosition), 1000, null); 
} 
}); 

答えて

0

解決済み。私はただ真実を返す必要がある。 falseを返すと、ClusterManagerは常にマークを画面の中央に表示します。

関連する問題