私はGoogleマップ上にポリラインのリストを描いています。描画されたポリラインに応じてマップのズームに合わせるソリューションを探しています。私はすべてのポリラインの中心点を計算したので、どの点を中心にしているのか分かります。しかし、ズームレベルを取得するための解決策はありません。Android Googleマップ、ポリライン、ズーム
ここで私が使用するコード:
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(getZoomPoint(), 15));
private LatLng getZoomPoint() {
Double minLatitude = null;
Double minLongitude = null;
Double maxLatitude = null;
Double maxLongitude = null;
for (Feature feature : features) {
List<Coordinates> coordinates = ((LineString) feature.getGeometry()).getCoordinates();
for (Coordinates coordinate : coordinates) {
// --------------------------------------------------------- INITIALISATION
if (minLatitude == null) { // No matter on wich var we check
minLatitude = coordinate.getLatitude();
minLongitude = coordinate.getLongitude();
maxLatitude = coordinate.getLatitude();
maxLongitude = coordinate.getLongitude();
} else {
if (coordinate.getLatitude() < minLatitude) {
minLatitude = coordinate.getLatitude();
}
if (coordinate.getLatitude() > maxLatitude) {
maxLatitude = coordinate.getLatitude();
}
if (coordinate.getLongitude() < minLongitude) {
minLongitude = coordinate.getLongitude();
}
if (coordinate.getLongitude() > maxLongitude) {
maxLongitude = coordinate.getLongitude();
}
}
}
}
double meanLatitude = (minLatitude + maxLatitude)/2;
double meanLongitude = (minLongitude + maxLongitude)/2;
return new LatLng(meanLatitude, meanLongitude);
}
私の最初の質問は:ズームレベルの値を計算する方法はありますか? (ここでは '15'がハードコードされています)。
私の2番目の質問は、どのようにカメラのズームレベルに応じてポリラインの幅を調整できますか?
mMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.d("ZOOM = ", "" +mMap.getCameraPosition().zoom);
});
そして私はsetWidth(...)
メソッドを使用してポリラインの幅を変更することができますが、私は幅の値を計算する「式」を見つけていない:私は、リスナーを追加しました。さて、修正されていないポリラインはズームレベルに依存します。
提案がありますか?