Android maps v2 - get map zoom

前提是你 提交于 2019-12-25 02:46:34

问题


I am trying to get the android map to zoom on my marker & leave the marker in the center of the screen.

public void onNewLocation(Location location, String name) {
    if (marker == null){
        marker = new MarkerOptions().position(new LatLng(
        location.getLatitude(), 
        location.getLongitude()))
        .title(preferencesUtils.getName(getApplicationContext(), preName, key));    
    }
    map.clear();
    marker.position(new LatLng(location.getLatitude(), location.getLongitude()));
    map.addMarker(marker);                  
}

this is the code - what should i add to zoom my marker


回答1:


To simply zoom in, use:

float zoomLevel = 20.0f;
map.animateCamera(CameraUpdateFactory.zoomTo(zoomLevel);

To zoom to the marker, use:

LatLng l = new LatLng(LATPOSITION, LONGPOSITION);
float zoomLevel = 20.0f;
map.animateCamera(CameraUpdateFactory.newLatLngZoom(l, zoomLevel));

Add these where you want the zoom to happen.



来源:https://stackoverflow.com/questions/20803568/android-maps-v2-get-map-zoom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!