簡體   English   中英

如何在地圖V2中的運行時對Camera進行動畫處理

[英]How to animateCamera at run time in Map V2

我是android新手,正在制作具有Google Map V2的應用程序。 我想在運行時對Camera Zoom值進行動畫處理。 它應取決於當前位置(緯度和經度)和目標位置(目的地緯度和經度)。

它應該是Zoom,這樣它應該盡可能顯示兩個標記,並且在mapv2上不需要任何平移,放大/縮小手勢。

我使用了這段代碼,但是我需要平移手勢才能在地圖上看到兩個市場。 我希望它應盡可能接近默認值,並且不需要任何平移手勢。

map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12.0f));

提前致謝。

您需要使用newLatLngBounds()

Returns a CameraUpdate that transforms the camera such that the specified latitude/longitude bounds are centered on screen at the greatest possible zoom level. You can specify padding, in order to inset the bounding box from the map view's edges. The returned CameraUpdate has a bearing of 0 and a tilt of 0.

找出兩個點的邊界框,並給出西南最多的點和東北最多的點

例:

map.animateCamera(CameraUpdateFactory.newLatLngBounds(new LatLngBounds(southWest,northEast),10));

要獲取邊界框,您需要遍歷所有點並找到最大/最小緯度/經度

例:

for(//for loop){
    LatLng point = new LatLng(lat,lng)

    if(point.getLatitude() > maxLat){
        maxLat = point.getLatitude();
    }
    if(point.getLatitude() < minLat){
        minLat = point.getLatitude();
    }
    if(point.getLongitude() > maxLon){
        maxLon = point.getLongitude();
    }
    if(point.getLongitude() < minLon){
        minLon = point.getLongitude();
    }
}

northEast = new LatLng(maxLat,maxLon);
southWest = new LatLng(minLat,minLon);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM