2013-06-08 38 views
14

Khi tôi khởi chạy bản đồ Google trong Android, nó sẽ hiển thị toàn thế giới. Tôi cần phải thay đổi gì để đặt mức thu phóng cho điểm đánh dấu? Đây là các mã. Cảm ơnGoogle Maps v2 Đặt mức thu phóng

 googlemap.getUiSettings().setZoomControlsEnabled(true); 
    googlemap.getUiSettings().setMyLocationButtonEnabled(true); 


    LatLng cameraLatLng = sfLatLng; 
    float cameraZoom = 17; 


    if(savedInstanceState != null){ 
     mapType = savedInstanceState.getInt("map_type", GoogleMap.MAP_TYPE_NORMAL); 

     double savedLat = savedInstanceState.getDouble("lat"); 
     double savedLng = savedInstanceState.getDouble("lng"); 
     cameraLatLng = new LatLng(savedLat, savedLng); 

     cameraZoom = savedInstanceState.getFloat("zoom", 30); 

     googlemap.setMapType(mapType); 
     googlemap.animateCamera(CameraUpdateFactory.newLatLngZoom(cameraLatLng, cameraZoom)); 

Trả lời

4

Các mã sau đây có thể làm các trick:

function addMarker(lat, lng, info) { 
    var pt = new google.maps.LatLng(lat, lng); 
    bounds.extend(pt); 

Bạn có thể thử cách sau quá:

var pt = new google.maps.LatLng(lat, lng); 
    map.setCenter(pt); 
    map.setZoom(your desired zoom); 

Edit:

map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f));//where 14.0 is the zoom level 
+0

Được thiết Chức vụ của tương tự như setCenter, nếu như vậy, tôi đã làm điều đó, nhưng không có tài sản để setZoom ... – 1088

+0

thấy chỉnh sửa ... – amalBit

41

thử này-- ->

map.addMarker(new MarkerOptions().position(latlng)).setVisible(true); 

    // Move the camera instantly to location with a zoom of 15. 
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(latlng, 15)); 

    // Zoom in, animating the camera. 
    map.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null); 
+0

Làm việc rất tốt. Cảm ơn rất nhiều – 1088

+6

@ matic1088 nếu điều này đã giúp bạn, chấp nhận câu trả lời này. –

+0

cách thực hiện tương tự (tức là thiết lập mức thu phóng) khi sử dụng LatLngBounds? – NarendraJi

1

Nếu bạn có Địa điểm (hoặc giới hạn), bạn có thể phóng to đến đó. Ví dụ. zoom đến quốc gia cụ thể, thành phố hoặc địa chỉ với .newLatLngBounds() phương pháp:

map.animateCamera(CameraUpdateFactory.newLatLngBounds(place.getViewport(), 10)); // 10 is padding 

Mức thu phóng sẽ được chọn tự động. Nó hoạt động hoàn hảo với tìm kiếm vị trí.

4
mMap.animateCamera(CameraUpdateFactory.zoomTo(19)); 
0
private GoogleMap mMap; 


    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 
     mMap.setMinZoomPreference(3.0f); 
     mMap.setMaxZoomPreference(5.5f); 
    } 
Các vấn đề liên quan